繁体   English   中英

将元组中的嵌套列表放入 numpy-array 中而不会丢失它们的维度

[英]Nested lists in tuple into numpy-array without losing their dimensions

如何在不丢失维度的情况下将嵌套列表元组转换为单个 numpy 数组?

嵌套列表元组:

([[3,4],[3,4]],[[4,5]])

结果 numpy-array 应该是:

[[[3,4],[3,4]],[[4,5]]]
In [146]: np.array(([[3,4],[3,4]],[[4,5]]))
<ipython-input-146-07d091c86ada>: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(([[3,4],[3,4]],[[4,5]]))
Out[146]: array([list([[3, 4], [3, 4]]), list([[4, 5]])], dtype=object)

结果是一个包含两个给定列表的数组(保留它们的维度)。 你还想要什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM