numpy.ascontiguousarray
numpy.ascontiguousarray(a, dtype=None) [source]
参数: | a : 输入数组。 dtype : 返回数组的数据类型。 |
返回值: | out : 相同的shape和含量的连续数组一个, 与类型dtype 如果指定。 |
例子
>>> x = np.arange(6).reshape(2,3)
>>> np.ascontiguousarray(x, dtype=np.float32)
array([[0., 1., 2.],
[3., 4., 5.]], dtype=float32)
>>> x.flags['C_CONTIGUOUS']
True
注意:此函数返回一个至少具有一维(1-d)的数组,因此它将不保留0-d数组。
文档:numpy.ascontiguousarray.html