first you have to remember that in Python there are no arraysunless you're working with numpy and variable X it's kind of numpy.array, second lists don't have a method apply() only DataFrames And you're not working with one. Finally your expression lambda is wrong, including X[:,0] (I don't know why you're doing that.) For your problem we will solve it using the function map() together with a lambda expression, to access each element we will use the syntax X[0],X[1] to access the first and second element correspondingly.the operation map() will return a list with the values obtained according to the last lambda expressionFrom what I see you compare with t, so if you say it should be greater than 0.5 and less than 0.3 t=[0.5,0.3]t = [0.5,0.3]
#pondra 0 si el primer valor es menor que 0.5 el segundo es mayor 0.3, de lo contrario 1
y_new = map(lambda x: 0 if x[0]<0.5 and x[1]>0.3 else 1, X)
#es lo mismo que
#y_new = map(lambda x: 0 if x[0]<t[0] and x[1]>t[1] else 1, X)
#para ver sus elementos lo convertimos a lista
y_new = list(y_new)
#imprimimos
print(y_new)
Dando as a result[1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0]
In a comment you said it was a Numpy.array(), in this case also works the lambda expression import numpy as np
X = np.array([[0.5 , 0.65],
[0.75, 0.34],
[0.37, 0.5 ],
[0.57, 0.74],
[1. , 0.69],
[0.1 , 0.61],
[0.04, 0.36],
[0.56, 0.45],
[0.46, 0.01],
[0.46, 0.97],
[0.26, 0.83],
[0.47, 0.01],
[0.34, 1. ],
[0.85, 0.41],
[0. , 0.72],
[0.66, 0.08],
[0.3 , 0.19],
[0.71, 0. ],
[0.3 , 0.77],
[0.17, 0.96]])
y_new = map(lambda x: 0 if x[0]<0.5 and x[1]>0.3 else 1, X)
#es lo mismo que
#y_new = map(lambda x: 0 if x[0]<t[0] and x[1]>t[1] else 1, X)
y_new = list(y_new)
print(y_new)
Departure[1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0]
If you want to get the value Boolean we can do it by transforming it with function bool(), this by means of a list compressiony_new = [bool(val) for val in y_new]
print(y_new)
Departure[True, True, False, True, True, False, False, True, True, False, False, True, False, True, False, True, True, True, False, False]
And as I said in a comment you can deny that.y_new = [not bool(val) for val in y_new]
print(y_new)
Departure[False, False, True, False, False, True, True, False, False, True, True, False, True, False, True, False, False, False, True, True]