当前位置: 移动技术网 > IT编程>脚本编程>Python > Python中shape计算矩阵的方法示例

Python中shape计算矩阵的方法示例

2017年12月12日  | 移动技术网IT编程  | 我要评论

启东事件图片,12影城网,90后辣妈amandashan

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网