NumPy: asanyarray() function
numpy.asanyarray() function
The asanyarray() function is used to convert an given input to an ndarray, but pass ndarray subclasses through.
Syntax:
numpy.asanyarray(a, dtype=None, order=None)
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. | Required |
dtype | By default, the data-type is inferred from the input data. | Optional |
order | Whether to use row-major (C-style) or column-major (Fortranstyle) memory representation. Defaults to 'C'. | Optional |
Return value:
out [ndarray or an ndarray subclass] Array interpretation of a. If a is an ndarray or a subclass of ndarray, it is returned as-is and no copy is performed.
Example-1: numpy.asanyarray()
>>> import numpy as np
>>> x = [4, 6]
>>> np.asanyarray(x)
array([4, 6])
Example-2: numpy.asanyarray()
>>> import numpy as np
>>> x = np.array([(2.0, 3), (4.0, 5)], dtype='f4,i4').view(np.recarray)
>>> np.asanyarray(x) is x
True
Python - NumPy Code Editor:
Previous: asarray()
Next: asmatrix()
- 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