0

I have a numpy array a of shape [300, 3, 3], I like to change this array - [0.7, 0.3, 0.1] to [1, 1, 1], if occured in a

For example,

Input -

b = np.array([[[0.7, 0.3, 0.1], [0.6, 0.4, 0.2], [0.1, 0.2, 0.1]],
             [[0.7, 0.3, 0.1], [0.6, 1.2, 2.1], [1.1, 2.1, 1.1]]
             ])

Output-

np.array([[[1, 1, 1], [0.6, 0.4, 0.2], [0.1, 0.2, 0.1]],
         [[1, 1, 1], [0.6, 1.2, 2.1], [1.1, 2.1, 1.1]]
         ])

How to achieve this in easiest way, without use of looping, thanks

0

2 Answers 2

3

Use where method to replace elements of array.

b = np.where(b == [0.7, 0.3, 0.1], [1, 1, 1], b)
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

np.where(b == [0.7, 0.3, 0.1], [1, 1, 1], b)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.