脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python中shape计算矩阵的方法示例

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

2020-09-30 14:02我要的shine Python

这篇文章主要介绍了Python中shape计算矩阵的方法,涉及Python数学运算相关实现技巧,需要的朋友可以参考下

本文实例讲述了Python中shape计算矩阵的方法。分享给大家供大家参考,具体如下:

看到机器学习算法时,注意到了shape计算矩阵的方法接下来就讲讲我的理解吧

?
1
2
3
4
5
6
>>> from numpy import *
>>> import operator
>>> a =mat([[1,2,3],[5,6,9]])
>>> a
matrix([[1, 2, 3],
    [5, 6, 9]])
?
1
2
3
4
5
6
>>> shape(a)
(2, 3)
>>> a.shape[0] #计算行数
2
>>> a.shape[1] #计算列数
3

接下来是Python中的解释

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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程序设计有所帮助。

延伸 · 阅读

精彩推荐