这篇文章主要介绍了python中shape计算矩阵的方法,涉及python数学运算相关实现技巧,需要的朋友可以参考下
本文实例讲述了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,)以上就是shape计算矩阵的python代码示例的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号