numpy.tile(A,reprs)

numpy.tile

numpy.tile(A, reps)

This method will return a max( d, A.ndim) dimension array( d= len( reprs)).

ifd> A.ndim, it will return a d-dimension array by prepending new axes;

etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>>>a = np.array([[1,2,3],[1,2,3]])
>>>np.tile(a,(2,3,2))

[[[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]]

[[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]]]

if d< A.ndim, it will return an A.ndim-dimension array by prepending 1’s to it .
For example, for an shape of(1,2,2,3), a reps of (2,3) will be treated as (1,1,2,3)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>>>a = np.array([[[[1,2,3],[1,2,3]]]])
>>>np.tile(a,(2,2))

[[[[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]
[1 2 3 1 2 3]]]]

>>>a = np.array([[[[1,2,3],[1,2,3]]]])
>>>np.tile(a,(2,1,3))

[[[[1 2 3 1 2 3 1 2 3]
[1 2 3 1 2 3 1 2 3]]

[[1 2 3 1 2 3 1 2 3]
[1 2 3 1 2 3 1 2 3]]]]

numpy.sum()

numpy.sum()

numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)

axis

This is a litte complex. abs(axis) must be less than a.ndim.


dtype

1
2
3
4
>>>b=np.array([0.3,0.4,0.9,1.5,1.9])
>>>print(b.sum(dtype=np.int32))

2

keepdims

If this parameter is assigned to True, the it will return an array as dimension with the size that input array is

1
2
3
4
5
6
7
8
9
10
>>>b=np.array([[[0.3,0.4,0.9,1.5,1.9]]])
>>>print(b.sum())

5.0


>>>b=np.array([[[0.3,0.4,0.9,1.5,1.9]]])
>>>print(b.sum(keepdims=True))

[[[ 5.]]]