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教程栏目进行学习!
以上就是若何输入python中list的维度的具体内容,更多请存眷资源魔其它相干文章!
标签: python教程 python编程 python使用问题 如何输出python中list的维度
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!