0

I have this points ndarray.

In [141]: points
Out[141]:
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7]])

And I have this classifier that I classified the points into two classes

In [142]: i5
Out[142]: array([0, 0, 1, 1])

Note, the length of points and i5 are same.

I know that the two classes have these values.

In [143]: c
Out[143]:
array([[2, 3],
       [4, 5]])

I want to assign the points to the values that I have classified. The final result that i expect is

In [141]: points
Out[141]:
array([[2, 3],
       [2, 3],
       [4, 5],
       [4, 5]])

How can I mutate/change points based on c indexed on i5?

1 Answer 1

1

Just use i5 as an index array on c and assign the indexed view on c to points

import numpy as np

c = np.array([[2, 3],
              [4, 5]])

i5 = np.array([0, 0, 1, 1])

points = c[i5]

# [[2 3]
#  [2 3]
#  [4 5]
#  [4 5]]

Note: Based on how you've described the problem, the initial value of points doesn't appear to matter. Is that an appropriate conclusion to derive?

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

1 Comment

only after I wrote this question, I realized that after calculating the classification values i5 (using values in points), they are not used. So, you described is a correct solution for me.

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.