How to replace values in a numpy array? I'm learning how to implement and evaluate a Logistic Regression Model, for this I need to change the values of my array from strings to 0 &amp; 1.
I have the following numpy ndarray as a result of a DataFrame.values call
['PAIDOFF', 'COLLECTION', 'COLLECTION', 'PAIDOFF', 'PAIDOFF', 'PAIDOFF', ...]
I would like to know how can I change the values like:
'PAIDOFF' to 0 and 'COLLECTION' to 1
Any help will be much appreciated
import numpy as np

a = np.array(['PAIDOFF', 'COLLECTION', 'COLLECTION', 'PAIDOFF'])

f = lambda x: 1 if x == &quot;COLLECTION&quot; else 0

np.fromiter(map(f,a),dtype=np.int)

Alternative:
np.where(a == &quot;COLLECTION&quot;,1,0)