【发布时间】:2022-06-11 00:36:52
【问题描述】:
我有以下计算网格和向量相乘的代码:
import numpy as np
Grid = np.ogrid[0:512, 0:512, 0:256]
Vec = np.array([1, 2, 3])
res = Vec @ Grid
警告是:
<stdin>:1: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
为什么会出现警告,我应该如何以一种好的方式将其删除?
【问题讨论】:
-
警告中给出了原因(不推荐从不规则的嵌套序列创建 ndarray)和解决方法(指定 'dtype=object')。那么你的问题到底是什么。你不能按照建议做吗?
-
@Stef 我有一个上面定义的
Grid。Grid中节点的坐标为A。A是一个 (3, 512*512*256) 矩阵,我要计算Vec @ A。 -
@Stef 在这种情况下如何指定'dtype=object'?
-
你真的看过
grid吗?grid.shape是什么?
标签: numpy