Before I forget - logical_and from Numpy

I keep coming back to needing this function, each time forgetting where to find it - populating an array based on conditions of other arrays which act as an input.

> np.logical_and()

Example

import numpy as np

# You have two arrays:

a = np.asarray([0,1,1,0,1,1,1,0])
b = np.asarray([2,3,5,1,6,7,3,8])

# Make another array which you'll later populate

c = np.zeros(a.shape) # array to be populatted using condition

# Populate c based on value conditions of arrays a and b

c[np.logical_and(a==1,b==3)] = 2 
Written on March 16, 2015