# 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 & 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 == "COLLECTION" else 0

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


Alternative:

np.where(a == "COLLECTION",1,0)

• So simple, thank you very much! Jan 7 at 22:12