0

I'm new to python and I'm trying to convert a (m,n,1) multidimensional array to (m,n) in a fast way, how can I go about it?

Also given a (m,n,k) array how can I split it to k (m,n) arrays? (each of the k members belongs to a different array)

K41F4r
  • 1,443
  • 1
  • 16
  • 36

2 Answers2

3

To reshape array a you can use a.reshape(m,n).

To split array a along the depth dimension, you can use numpy.dsplit(a, a.shape[2]).

https://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html https://docs.scipy.org/doc/numpy/reference/generated/numpy.dsplit.html#numpy.dsplit

nkaushik
  • 71
  • 4
1

To reshape a NumPy Array arr with shape (m, n, 1) to the shape (m, n) simply use:

arr = arr.reshape(m, n)

You can get a list of (m, n)-shaped arrays out of a (m, n, k) shaped array arr_k by:

array_list = [arr_k[:, :, i] for i in range(arr_k.shape[2])]
randomwalker
  • 1,573
  • 1
  • 9
  • 14