I would like to be able to perform operations on specific elements in a 2D array, if it meets a criterion. in the below example the code makes any value < 0.5 = 0.
Does anyone know of a simple way of doing this? Below is my code, but im sure there is a simpler way.
import numpy as np
x = 5
y = 5
x3 = np.random.rand(x,y)
def choice(arr):
row = -1
column = -1
for i in arr:
row += 1
for j in i:
column += 1
if j >= 0.5:
arr[row,column] = j
else:
arr[row,column] = 0
if column == y - 1:
column = -1
return arr
y3 = choice(x3.copy())