python:numpy--function Shape usage

Source: Internet
Author: User

A shape function is a function in a numpy.core.fromnumeric that looks at the dimension of a matrix or array.

An example is provided:

Establish a 3x3 unit matrix E, E.shape (3,3), which represents 3 rows of 3 columns, the first dimension is 3, and the second dimension is 3.

>>> e = Eye (3)
>>> e
Array ([[1.,  0.,  0.],
       [0.,  1.,  0.],
       [0.,  0.,  1.]]
>>> e.shape
(3, 3)
Establish a one-dimensional matrix B, b.shape as the length of the matrix
>>> b =array ([1,2,3,4])
>>> b.shape
(4,)
#可以简写
>>> shape ([1,2,3,4])
(4,)
>>> 

Establish a 4x2 matrix C, c.shape[1] for the length of the first dimension, c.shape[0] for the length of the second dimension.

>>> C = Array ([[[1,1],[1,2],[1,3],[1,4]])
>>> c.shape
(4, 2)
>>> c.shape[0]
4
>>> c.shape[1]
2
A single value, the return value is null

>>> shape (3)
()



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.