将列表转换为数组时减少维度 [英] Reduce Dimensons when converting list to array
本文介绍了将列表转换为数组时减少维度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在将数组转换为列表后减小数组的尺寸
I want to reduce the dimensions of an array after converting it to a list
a = np.array([[1,2],[3,4]])
print a.shape
b = np.array([[1],[3,4]])
print b.shape
输出:
(2, 2)
(2,)
我希望a与b具有相同的形状,即(2,)
I want a to have the same shape as b i.e. (2,)
推荐答案
>>> a = np.array([[1,2],[3,4], None])[:2]
>>> a
array([[1, 2], [3, 4]], dtype=object)
>>> a.shape
(2,)
工程,但是可能是错误的方法(我是个笨拙的新手).
Works, though is probably the wrong way to do it (I'm a numpy newb).
这篇关于将列表转换为数组时减少维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文