Add a dimmension (other than "1")

  numpy, python

If I have a matrix matrix1 like

[[80 80 80 80]
 [ 0 50  0  0]
 [ 0  0 50  0]
 [ 0  0  0 50]
 [30 30 30 30]]

which is shape (5,4) and I do matrix2=matrix[...,np.newaxis] I get a matrix with shape:
(5,4,1)

My question is, how can I get a matrix of shape (5,4,n) with n being any number other than 1?

Source: Python Questions

LEAVE A COMMENT