如何将2d列表转换为2d numpy数组? [英] how to convert 2d list to 2d numpy array?
本文介绍了如何将2d列表转换为2d numpy数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
,我想将其转换为2d numpy数组.我们可以在不分配
and I want to convert it to a 2d numpy array. Can we do it without allocating memory like
numpy.zeros((3,3))
然后将值存储到其中?
推荐答案
只需将列表传递给np.array
:
a = np.array(a)
如果默认值不是您想要的值,您还可以借此机会设置dtype
.
You can also take this opportunity to set the dtype
if the default is not what you desire.
a = np.array(a, dtype=...)
这篇关于如何将2d列表转换为2d numpy数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文