http://blog.csdn.net/u010758410/article/details/71554224
The shape function is a function in numpy.core.fromnumeric, and its function is to look at the dimensions of a matrix or array.
To illustrate:
Create a 3x3 unit matrix E, E.shape (3,3), which represents 3 rows and 3 columns, the first dimension is 3, and the second dimension is 3
[Plain]View Plain Copy
- >>> e = Eye (3)
- >>> E
- Array ([[1., 0., 0.],
- [0., 1., 0.],
- [0., 0., 1.]])
- >>> E.shape
- (3, 3)
[Plain]View PlainCopy
- >>> 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
[Plain]View Plain Copy
- >>> b =array ([1,2,3,4])
- >>> B.shape
- (4,)
- #可以简写
- >>> shape ([1,2,3,4])
- (4,)
- >>>
[Plain]View PlainCopy
- >>> b =array ([1,2,3,4])
- >>> B.shape
- (4,)
- #可以简写
- >>> shape ([1,2,3,4])
- (4,)
- >>>
Establish a 4x2 matrix C, c.shape[1] is the length of the first dimension, c.shape[0] is the length of the second dimension.
[Plain]View Plain Copy
- >>> C = Array ([[[1,1],[1,2],[1,3],[1,4]])
- >>> C.shape
- (4, 2)
- >>> C.shape[0]
- 4
- >>> C.shape[1]
- 2
[Plain]View PlainCopy
- >>> 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 that returns a null value
[Plain]View Plain Copy
- >>> shape (3)
- ()
[Plain]View PlainCopy
- >>> shape (3)
- ()
python:numpy--function Shape usage