NumPy Array manipulation: asfarray() function

numpy.asfarray() function

The asfarray() function is used to convert an given input to an ndarray, but pass ndarray subclasses through.


numpy.asfarray(a, dtype=<class 'numpy.float64'>)
NumPy manipulation: asfarray() function

Version: 1.15.0


Name Description Required /
a Input data, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays. Requireed
dtype Float type code to coerce input array a. If dtype is one of the 'int' dtypes, it is replaced with float64. Optional

Return value:

out : ndarray The input a as a float ndarray.

Example-1: numpy.asfarray()

>>> import numpy as np
>>> np.asfarray([5, 7])
array([ 5.,  7.])

Pictorial Presentation:

NumPy manipulation: asfarray() function

Example-2: numpy.asanyarray()

>>> import numpy as np
>>> np.asfarray([5, 7], dtype='float')
array([ 5.,  7.])
>>> np.asfarray([5, 7], dtype='int8')
array([ 5.,  7.])

Python - NumPy Code Editor:

Previous: asmatrix()
Next: asfortranarray()