I have a one column numpy array with multiple elements. I want to write a function that takes each element and evaluates if it meets a condition. Then depending on the result, it should use equations to calculate something. The calculation result should have the same size as the input array.
This is a simple example of what I want to do. (The actual code will be more complex). I know why it doesn't work but can't seem to find a solution.
import numpy as np
array1 = np.arange(1,11,1)
def test(array1):
value1 = 20
i = 0
value3 = array1[i]
while array1 > value3 and i < value1:
i =+ 1
value3 = array1[i]
test(array1)
I have tried to find a solution:
- I looked at any() and all(), but it isnt't what I need, since I want to look at each element seperately.
- I looked at numpy.where() but it return only the elements that meet a condition and therefor changes the array size, which isn't what I want.
EDIT: For my complete solution both the for loop version by Zulfiqaar and the where function as shown by Siva Kowuru are possible. Since the where function seems faster and more convenient I marked it as the accepted answer.
np.whereis the way to go, see the answer of @SivaKowuru below.