Ewig
V2EX  ›  Python

Python numpy 如何看几维?

By Ewig at 2019 年 1 月 19 日 · 3930 次点击
>>> 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) 这个是二维的图怎么画出来啊
4 条回复  •  2019-01-21 09:27:27 +08:00
aijam
   1
aijam  
   2019 年 1 月 19 日
这个很简单啊
dangyuluo
   2
dangyuluo  
   2019 年 1 月 19 日
不看文档的么。。。
```python
a.dim
```
xiao38245
   3
xiao38245  
   2019 年 1 月 19 日
a.shape, 好好看看文档吧
Zeeech
   4
Zeeech  
   2019 年 1 月 21 日
@dangyuluo 正解
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
© 2026 V2EX · 29ms · 3.9.8.5