V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
Ewig
V2EX  ›  Python

Python numpy 如何看几维?

  •  
  •   Ewig · 2019-01-19 01:35:43 +08:00 · 2917 次点击
    这是一个创建于 1895 天前的主题,其中的信息可能已经有所发展或是发生改变。
    >>> 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-01-19 06:01:29 +08:00
    这个很简单啊
    dangyuluo
        2
    dangyuluo  
       2019-01-19 08:45:39 +08:00
    不看文档的么。。。
    ```python
    a.dim
    ```
    xiao38245
        3
    xiao38245  
       2019-01-19 11:36:40 +08:00
    a.shape, 好好看看文档吧
    Zeeech
        4
    Zeeech  
       2019-01-21 09:27:27 +08:00
    @dangyuluo 正解
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1677 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 98ms · UTC 16:45 · PVG 00:45 · LAX 09:45 · JFK 12:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.