python中输出pst的维度可以使用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教程栏目进行学习!
以上就是小编分享的关于如何输出python中list的维度的详细内容希望对大家有所帮助,更多有关python教程请关注环球青藤其它相关文章!