0

i have a 3d array in this form (12457,8,6) i wand to divide it into 2 equal numpy arrays like (12457,3,8) In fact that the first one containt the first 3 bands and the second one contains the remaind bands: In other words I want my array1 contains the bands 1,2,3 and my array2 contains the bands 4,5,6

I tried with that but it doesnt work

array1=data[:,:,3]
array1.shape
(12457,8)

2 Answers 2

2

You can use np.split -

X = np.random.random((1200,6,8))
print(X.shape)

X1, X2 = np.split(X, 2, axis=1) #Array, num of splits, axis for splitting
print(X1.shape, X2.shape)
(1200, 6, 8)
(1200, 3, 8) (1200, 3, 8)
Sign up to request clarification or add additional context in comments.

1 Comment

Read more here.
0

split or array_split should be able to help you out.

import numpy as np

arr = np.array([[1,2,3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
newarr = np.split(arr, 2)
print(newarr)

Prints:

[array([[1, 2, 3],
       [4, 5, 6]]), array([[ 7,  8,  9],
       [10, 11, 12]])]

3 Comments

Hi UncleCid, welcome to SO. This answer is exactly the same as one already answered. If you do see an answer please refrain from posting the same (in this case you posted the exact solution almost 5 minutes after it was already answered). Instead, just comment on the previous answer to add more value to it.
@AkshaySehgal I was busy writing the solution while that one was being posted. I didn't think to refresh the page to see if any solutions had appeared. I suppose I should delete it then?
No thats all right, these things happen. Its just a respected practice here, thats all.

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.