NumPy: ascontiguousarray() function
numpy.ascontiguousarray() function
The function ascontiguousarray() is used to get a contiguous array in memory (C order).
Syntax:
numpy.ascontiguousarray(a, dtype=None)
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
a | Input array. | Required |
dtype | Data-type of returned array. | Optional |
Return value:
out : ndarray - Contiguous array of same shape and content as a, with type dtype if specified.
Example: numpy.ascontiguousarray()
>>> import numpy as np
>>> a = np.arange(9).reshape(3, 3)
>>> np.ascontiguousarray(a, dtype=np.float32)
array([[ 0., 1., 2.],
[ 3., 4., 5.],
[ 6., 7., 8.]], dtype=float32)
>>> a.flags['C_CONTIGUOUS']
True
Pictorial Presentation:
Python - NumPy Code Editor:
Previous: asfortranarray()
Next: asarray_chkfinite()
- 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