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)

3
  • when you say "array" (the input one) what do you mean? can you show a code example Commented Feb 26, 2019 at 15:09
  • Why do you need to do the latter? What have you tried? This is pretty basic stuff, so can you at least show what documentation you have looked at? Commented Feb 26, 2019 at 15:09
  • It would help if you gave some toy data and an example of what you already tried. Commented Feb 26, 2019 at 15:22

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I like using dsplit, however the returned list will contain arrays of shape (m, n, 1)
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])]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.