user785099 - 1 year ago 65

Python Question

There has a nd array

`A`

`[100,255,255,3]`

`A1 = A[i,:,:,:]`

`A1`

`[255,255,3]`

`[1,255,255,3]`

Answer Source

Use `np.newaxis`

on your resulting array.

Very simple example on a 2d array:

```
x = np.array([[0, 1], [2, 3]])
x.shape
#: (2, 2)
x[np.newaxis]
#: array([[[0, 1],
#: [2, 3]]])
x[np.newaxis].shape
#: (1, 2, 2)
```