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'>)
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:
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()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework