2024-06-17 12:06:12 发布
网友
我有一个努比·恩达雷我需要计算它的梯度,得到一个新的具有相同维数的ndarray。我在用数字梯度但它返回的是一个列表。我怎么才能得到np.梯度返回np.ndarray?在
force = np.gradient(phi)*(-1)
其中phi是我的300立方矩阵,我一直得到
文档说gradient返回一个(列表)N arrays of the same shape asfgiving the derivative offwith respect to each dimension.
gradient
N arrays of the same shape as
giving the derivative of
with respect to each dimension.
np.gradient中的一个示例返回一个list-一个由2个数组组成的列表
np.gradient
In [105]: np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)) Out[105]: [array([[ 2., 2., -1.], [ 2., 2., -1.]]), array([[-0.5, 2.5, 5.5], [ 1. , 1. , 1. ]])]
一维输入产生一个数组
一个3d数组为我提供了3个数组的列表:
In [110]: len(np.gradient(np.ones((30,30,30)))) Out[110]: 3
文档说
gradient
返回一个(列表)N arrays of the same shape as
fgiving the derivative of
fwith respect to each dimension.
np.gradient
中的一个示例返回一个list-一个由2个数组组成的列表一维输入产生一个数组
^{pr2}$一个3d数组为我提供了3个数组的列表:
相关问题 更多 >
编程相关推荐