gpt4 book ai didi

python - 如何将形状数组 n, 转换为 n,m

转载 作者:行者123 更新时间:2023-12-04 02:35:03 25 4
gpt4 key购买 nike

我正在尝试将形状为 (80000,) 的 numpy 数组转换为 (80000,55)我有如下数据[[1212,121,121],[12,122,111]]转换此列表列表后,我得到了 (2,) 的形状,但我想要像 (2,3) 这样的形状如何去做。

最佳答案

In [68]: np.array([[1212,121,121],[12,122,111]] )                                                               
Out[68]:
array([[1212, 121, 121],
[ 12, 122, 111]])
In [69]: _.shape
Out[69]: (2, 3)

如果您得到类似 (2,) 的形状,可能是因为某些嵌套列表的形状不同。检查 dtype 以及 shape。还要查看数组。

In [70]: np.array([[1212,121,121],[12,122,111,3]] )                                                             
Out[70]: array([list([1212, 121, 121]), list([12, 122, 111, 3])], dtype=object)

即将发布的版本将添加警告:

/usr/local/bin/ipython3: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
#!/usr/bin/python3

关于python - 如何将形状数组 n, 转换为 n,m,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62364203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com