教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 如何输出python中list的维度

如何输出python中list的维度

发布时间:2020-10-30   编辑:jiaochengji.com
教程集为您提供如何输出python中list的维度等资源,欢迎您收藏本站,我们将为您提供最新的如何输出python中list的维度资源

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中list的维度
    python如何减小维度
    Python中numpy如何切片
    python如何设计矩阵
    python如何对list求和
    python数组和列表区别
    关于numpy的问题
    python常见的排序算法有哪些?
    Python中numpy多维数组的用法
    python中的rfind函数如何使用

    [关闭]
    ~ ~