python中输出list的维度可以使用numpy来实现:import numpy as np
a = [[1,2],[3,4]]
print(np.array(a).shape)
扩展:
reshape&resize&shape改变数组维度
reshape函数:不改变原数组维度,有返回值
resize函数:直接改变原数组维度,无返回值
shape属性:直接改变原数组维度>>> import numpy as np
>>> a=np.arange(12)
>>> a
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
>>> a.reshape(2,6)
array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11]])
>>> a
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
>>> a.reshape(2,3,2)
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]]])
>>> a.resize(2,6)
>>> a
>>> array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11]])
>>> a.shape=(2,6)
>>> a
array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11]])
>>> a.shape=(2,3,2)
>>> a
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]]])
>>>
更多Python相关技术文章,请访问Python教程栏目进行学习!
本文地址:http://itbyc.com/Python/22256.html
转载请注明出处。
1936

被折叠的 条评论
为什么被折叠?



