I want to turn every 0 of a large array list into a -1. This has do be done as quickly as possible. A for loop is very slow for me. My array is a numpy array. Does you know a faster solution for this simple problem?
Here is a example code:
test_array=[1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 0]
for index, value in enumerate(test_array):
if value == 0:
l[index] = -1
test_array=[1 -1 -1 1 -1 -1 1 1 -1 1 1 -1 1 -1 -1 -1]
My real list is a lot longer than the one in this example, so a quick solution is a performance factor.