为什么 3d 不需要 ddtype?

Why 3d doesnt want ddtype?

当我尝试使用 ndarray 创建 2-D 数组时,如果我没有指定 ddtype 值,它会给我错误,但是当尝试创建 3-D 数组时,它没有为什么,我的意思是有这样的规则那?

import numpy as np
array=np.array([[1,1,1,1,1,1],[1,1,2,1,1,1,1]])


print(array)
print(array.ravel())

我收到以下错误:

c:/Users/fazil/Desktop/yeni metin belgesi.py:2: 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 array=np.array([[1,1,1,1,1,1],[1,1,2,1,1,1,1]]) [list([1, 1, 1, 1, 1, 1]) list([1, 1, 2, 1, 1, 1, 1])] [list([1, 1, 1, 1, 1, 1]) list([1, 1, 2, 1, 1, 1, 1])]

该警告告诉您子列表的长度不同,因此无法生成二维数值数组。将来您将必须提供 dtype。现在你只是挨骂。

In [217]: np.array([[1,1,1,1,1,1],[1,1,2,1,1,1,1]])
     ...: 
<ipython-input-217-a5da97fcce54>: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
  np.array([[1,1,1,1,1,1],[1,1,2,1,1,1,1]])
Out[217]: 
array([list([1, 1, 1, 1, 1, 1]), list([1, 1, 2, 1, 1, 1, 1])],
      dtype=object)
In [218]: x=np.array([[1,1,1,1,1,1],[1,1,2,1,1,1,1]], object)
     ...: 
     ...: 
In [219]: 
In [219]: x
Out[219]: 
array([list([1, 1, 1, 1, 1, 1]), list([1, 1, 2, 1, 1, 1, 1])],
      dtype=object)
In [220]: len(x[0])
Out[220]: 6
In [221]: len(x[1])
Out[221]: 7

该警告与 2d 与 3d 无关,甚至与子列表的数量无关。如果您的其他尝试在没有警告的情况下成功,则它必须具有相等长度的子列表。