Python中shape计算矩阵的方法示例 本文实例讲述了Python中shape计算矩阵的方法。分享给大家供大家参考,具体如下: 看到机器学习算法时,注意到了shape计算矩阵的方法接下来就讲讲我的理解吧 >>> from numpy import * >>> import operator >>> a =mat([[1,2,3],[5,6,9]]) >>> a matrix([[1, 2, 3], [5, 6, 9]]) >>> shape(a) (2, 3) >>> a.shape[0] #计算行数 2 >>> a.shape[1] #计算列数 3 接下来是Python中的解释 Examples -------- >>> np.shape(np.eye(3)) (3, 3) >>> np.shape([[1, 2]]) (1, 2) >>> np.shape([0]) (1,) >>> np.shape(0) () >>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (2,) >>> a.shape (2,) 更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》 希望本文所述对大家Python程序设计有所帮助。