python - Apply formula to specific numpy array values -


i have 2 dimensional array in numpy , need apply mathematical formula values of array match criteria. can made using loop , if conditions think using numpy where() method works faster.

my code far doesn't work

cond2 = np.where((spn >= -alpha) & (spn <= 0)) spn[cond2] = -1*math.cos((spn[cond2]*math.pi)/(2*alpha)) 

the values in orginal array need replaced corresponding value after applying formula.

any ideas of how make work? i'm working big arrays need , efficient way of doing it. thanks

try this:

cond2 = (spn >= -alpha) & (spn <= 0) spn[cond2] = -np.cos(spn[cond2]*np.pi/(2*alpha)) 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -