There is a 1 dimensional numpy array named "target_y". My task is to ensure that "target_y" has all values encoded as 1 and -1, not 1 and 0 before performing logistic regression. Once I do it, I need to assign it to "prepared_y" and return it. Can I write something like:
numpy
"target_y"
1
-1
0
"prepared_y"
if target_y in 1,-1: prepared_y = target_y
To replace all 0 values with -1 in a numpy.array it’s as simple as:
numpy.array
a[a == 0] = -1
... where a is the 1 dimensional array.
a
2.1m questions
2.1m answers
60 comments
57.0k users