Python numpy 如何看几维?

2019-01-19 01:35:43 +08:00
 Ewig
>>> import numpy as np
>>> a=np.array([[1,2,3],[3,5,6]])
>>> b=np.array([1,2,3,4,5],ndmin=2)
>>> print(b)
[[1 2 3 4 5]]
>>> b.shape
(1, 5)
>>> com=np.array([a,b,c])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>> com=np.array([a,b,c])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>> c=np.array([[3,2,3],[3,5,6]])
>>> com=np.array([a,b,c])
>>> com
array([array([[1, 2, 3],
[3, 5, 6]]), array([[1, 2, 3, 4, 5]]),
array([[3, 2, 3],
[3, 5, 6]])], dtype=object)
>>> com.shape
(3,)
>>> b.shape
(1, 5)
>>> c.shape
(2, 3)
>>>


比如这个怎么看维度啊?(1, 5) 这个是二维的图怎么画出来啊
2943 次点击
所在节点    Python
4 条回复
aijam
2019-01-19 06:01:29 +08:00
这个很简单啊
dangyuluo
2019-01-19 08:45:39 +08:00
不看文档的么。。。
```python
a.dim
```
xiao38245
2019-01-19 11:36:40 +08:00
a.shape, 好好看看文档吧
Zeeech
2019-01-21 09:27:27 +08:00
@dangyuluo 正解

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/528474

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX