James A
James A

Reputation: 73

How to find elemental modulus of NumPy array

I would like to get the elemental modulus (each element of the array is modulated by number x and returned in array format) of the following numpy array:

    test = numpy.array([
              [5, 2],
              [1, 4]
           ])

How can I go about doing this?

Upvotes: 1

Views: 1487

Answers (1)

U13-Forward
U13-Forward

Reputation: 71610

Use numpy.mod, demo:

>>> import numpy
>>> test = numpy.array([
              [5, 2],
              [1, 4]
           ])
>>> numpy.mod(test,2)
array([[1, 0],
       [1, 0]], dtype=int32)
>>> 

Upvotes: 2

Related Questions