Name

putmask

Synopsis

putmask(a,mask,values)

a must be a contiguous array. mask is a sequence with the same length as a .flat. values is a sequence of values that can be converted to a’s type code (if shorter than mask, values is repeated as needed). Each element of a corresponding to a true item in mask is replaced by the corresponding item in values. putmask is therefore similar to (but faster than) the loop:

for i,v in zip(xrange(len(mask)),values*len(mask)):
    if mask[i]: a.flat[i]=v

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.