>我定义了一个Fortran连续数组:
import numpy as np
hp = np.zeros([number_fragments, max(length_fragments_list), 6], order='F')
此数组的切片不是 Fortran 连续的。我该如何解决这个问题?
hn = hp[0,0:Length-1,:]
hn.flags
C_CONTIGUOUS : False
F_CONTIGUOUS : False
also
hn = hp[0,0:Length-1,:].copy()
hn.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
切片后如何轻松获得 Fortran 连续数组?
您可以在切片上应用 numpy 函数np.asfortranarray
来强制执行它,例如:
np.asfortranarray(hp[0,0:Length-1,:].copy())