Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: asfarray() function

numpy.asfarray() function

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

Syntax:

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

Version: 1.15.0

Parameter:

Name Description Required /
Optional
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()