def toCArray(X, dtype=np.float64):
""" Convert input into numpy array of C-contiguous order.
Ensures returned array is aligned and owns its own data,
not a view of another array.
Returns
-------
X : ND array
Examples
-------
>>> Q = np.zeros(10, dtype=np.int32, order='F')
>>> toCArray(Q).flags.c_contiguous
True
>>> toCArray(Q).dtype.byteorder
'='
"""
X = np.asarray_chkfinite(X, dtype=dtype, order='C')
if X.dtype.byteorder != '=':
X = X.newbyteorder('=').copy()
if not X.flags.owndata or X.flags.aligned:
X = X.copy()
assert X.flags.owndata
assert X.flags.aligned
return X
评论列表
文章目录