In Python, I would like to have a function working on different input types. Something like this:
def my_square(x):
return x ** 2
my_square(2) #return 4
my_square(range(10)) #should return a list [0 ... 81]
npa = numpy.zeros(10)
my_square(npa) # should return a numpy array with the squares of zeros
Basically, what is good practice to write functions for both scalars and iterables? Can this be done with *args or *kwargs perhaps?