1

I have an array of size 80x40 and want to send each row into one of two smaller arrays based on a value in a specific column (10). I have code similar to below-but this ends up flattening the array. I don't know the Y dimensions of the output arrays (Array2,Array3). I guess I could have some code count all the values above and below 50 to get the Y dimensions of the output axes and then make 2 output arrays of np.zeros(Array.shape[0],Yvalues) and append row by row to that but I'm still not sure how that would work.

Array.shape=(80,40)
Array2=[]
Array3=[]

for x in range(0,Array.shape[0]):
    if Array[x,10]<50:
        Array2.append(Array[x,:])
    else:
        Array3.append(Array[x,:])

1 Answer 1

1

As a smaller example:

a = np.array([[1, 10], [1, 20], [2, 30], [2, 40], [1, 50], [3, 60], [1, 70]])

a2 = a[a[:, 0] < 1.5]
a3 = a[a[:, 0] >= 1.5]

a2 is now:

array([[ 1, 10],
       [ 1, 20],
       [ 1, 50],
       [ 1, 70]])

and a3 is now:

array([[ 2, 30],
       [ 2, 40],
       [ 3, 60]])

So in your case, use:

a2 = a[a[:, 10] < 50]
a3 = a[a[:, 10] >= 50]
Sign up to request clarification or add additional context in comments.

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.