NumPy: ascontiguousarray() function
ascontiguousarray() function
The ascontiguousarray() function 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:
[ndarray]
Contiguous array of same shape and content as a, with type dtype if specified.
Example-1: NumPy.ascontiguousarray() function
>>> import numpy as np
>>> a = np.arange(8). reshape (4, 2)
>>> np.ascontiguousarray(a, dtype=np.float32)
array([[ 0., 1.],
[ 2., 3.],
[ 4., 5.],
[ 6., 7.]], dtype=float32)
Pictorial Presentation:

Example-2: NumPy.ascontiguousarray() function
>>> import numpy as np
>>> a = np.arange(8). reshape (4, 2)
>>> np.ascontiguousarray(a, dtype=np.float32)
array([[ 0., 1.],
[ 2., 3.],
[ 4., 5.],
[ 6., 7.]], dtype=float32)
>>> a.flags['C_CONTIGUOUS']
True
Python - NumPy Code Editor:
Previous: asanyarray()
Next: asmatrix()
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises