Home > Software design >  Even number function and odd number function
Even number function and odd number function

Time:03-16

Does NumPy comes with a even number function and odd number function like

evenNum {} and oddNum {} so as to include it in other functions

CodePudding user response:

No, but you can easily write one yourself using the modulo operator.

def is_even(number):
    return number % 2 == 0

This will return True for even numbers and False for odd ones. See Wikipedia - Modulo operation for more info.

CodePudding user response:

Nope, but you can do something like:

MAX_NUMBER = 100
even = np.array([i for i in range(MAX_NUMBER) if i % 2 == 0])
odd = np.array([i for i in range(MAX_NUMBER) if i % 2 != 0])

Where MAX_NUMBER is the max number that you want to manage

  • Related