Numpy Array value replace with yesor no | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Numpy Array value replace with yesor no

In a numpy Array if it satisfying a condition then replace these value with yes otherwise replace with no with the help of np.where

27th Dec 2020, 6:52 PM
SAADAT ALI
3 Answers
+ 1
Np.where is necessary This code will work? Arr=([2,4,6,7,8,9]) Ans=np.where( (arr%3 ==0 & arr%==0)=True ,"yes", "no") Or Ans=np.where( (arr%3 ==0 & arr%==0) ,"yes", "no")
29th Dec 2020, 3:04 AM
SAADAT ALI
+ 1
Yes, it will work. My regards.
29th Dec 2020, 8:54 AM
Михаил Иванов
Михаил Иванов - avatar
0
Is it necessary to use np.where? You can write a function, for example: def fun(x): return 'yes' if condition else 'no' Vectorize it using np.vectorize and apply to your array.
28th Dec 2020, 10:36 PM
Михаил Иванов
Михаил Иванов - avatar