First page Back Continue Last page Overview Graphics

Operations, II

With scalars:

>>> x = np.arange(1,5)

>>> x + 3

array([4, 5, 6, 7])

>>> x * 4

array([ 4, 8, 12, 16])

>>> x ** 2

array([ 1, 4, 9, 16])

>>> 2 ** x

array([ 2, 4, 8, 16])

>>>

Logical operations:

>>> x = np.array([0, 1, -4, 0])

>>> y = np.array([1, 0, 15, 0])

>>> np.logical_and(x, y)

array([False, False, True, False], dtype=bool)

>>> np.logical_or(x, y)

array([ True, True, True, False], dtype=bool)

>>> np.logical_xor(x, y)

array([ True, True, False, False], dtype=bool)

>>> np.logical_not(x)

array([ True, False, False, True], dtype=bool)