python numpy set elements of list by condition -
i want set specific element of list specific value low overhead. example if have : a = numpy.array([1,2,3,0,4,0])
want change every 0 value 10; in end want have [1, 2, 3, 10, 4, 10]
in matlab can a(a==0) = 10, there equivalent in numpy?
remarkably similar matlab:
>>> a[a == 0] = 10 >>> array([ 1, 2, 3, 10, 4, 10])
there's nice "numpy matlab users" guide @ scipy website.
i should note, doesn't work on regular python lists. numpy arrays different datatype work lot more matlab matrix python list in terms of access , math operators.
Comments
Post a Comment