Python中shape计算矩阵的方法示例
作者:我要的shine 时间:2022-04-09 20:34:06
本文实例讲述了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,计算,矩阵
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python利用插值法对折线进行平滑曲线处理
2023-10-15 14:48:08
![](https://img.aspxhome.com/file/2023/0/128300_0s.jpg)
.NET 6中为record类型自定义Equals方法
2023-07-15 21:29:29
浅析python中SQLAlchemy排序的一个坑
2023-03-29 10:47:23
基于wxPython的GUI实现输入对话框(1)
2023-01-07 19:54:21
![](https://img.aspxhome.com/file/2023/5/124805_0s.jpg)
python实现的生成随机迷宫算法核心代码分享(含游戏完整代码)
2022-01-01 08:19:10
mysql数据库下损坏数据的恢复操作其过程总结
2009-02-13 13:36:00
Python入门教程(五)Python变量的用法
2021-04-05 11:17:35
![](https://img.aspxhome.com/file/2023/3/113123_0s.png)
python代码如何注释
2021-08-16 20:46:29
python爬虫豆瓣网的模拟登录实现
2023-07-08 20:28:08
![](https://img.aspxhome.com/file/2023/9/115439_0s.jpg)
分享一个Emeditor压缩样式的宏
2010-08-16 12:30:00
python中的hashlib和base64加密模块使用实例
2022-10-19 05:08:23
numpy.concatenate函数用法详解
2022-04-09 06:18:52
Python 调用 Outlook 发送邮件过程解析
2023-11-17 19:34:57
![](https://img.aspxhome.com/file/2023/6/63536_0s.png)
python去掉字符串中重复字符的方法
2022-11-23 09:17:35
python正则表达式去掉数字中的逗号(python正则匹配逗号)
2023-03-15 20:32:40
Python OpenCV 直方图的计算与显示的方法示例
2022-10-15 07:36:24
![](https://img.aspxhome.com/file/2023/8/120938_0s.jpg)
python从入门到实践之字典
2023-05-11 22:20:17
Python实现小黑屋游戏的完整实例
2021-03-08 13:27:43
![](https://img.aspxhome.com/file/2023/5/67745_0s.png)
python指定路径斜杠与反斜杠遇到的问题
2023-03-18 20:47:27
![](https://img.aspxhome.com/file/2023/6/123466_0s.png)
Python当中的array数组对象实例详解
2022-02-12 23:22:47
![](https://img.aspxhome.com/file/2023/8/81708_0s.png)