Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why tuple convention in function parameters?

I was wondering why many functions - especially in numpy - utilize tuples as function parameters?

e.g.:

a = numpy.ones( (10, 5) )

What could possibly be the use for that? Why not simply have something such as the following, since clearly the first parameters will always denote the size of the array?

a = numpy.ones(10, 5)

Is it because there might be additional parameters, such as dtype? even if so,

a = numpy.ones(10, 5, dtype=numpy.int)

seems much cleaner to me, than using the convoluted tuple convention.

Thanks for your replies

like image 727
Muppet Avatar asked Mar 16 '12 18:03

Muppet


Video Answer


1 Answers

Because you want to be able to do:

a = numpy.ones(other_array.shape)

and other_array.shape is a tuple. There are a few functions that are not consistent with this and work as you've described, e.g. numpy.random.rand()

like image 152
YXD Avatar answered Oct 16 '22 20:10

YXD