Style - was Re: numpy.repeat TypeError: array cannot be safely cast to required type
tim.hochberg at ieee.org
Sat Nov 4 14:23:11 CST 2006
Colin J. Williams wrote:
> Tim Hochberg wrote:
>> A style note: please use the named dtypes (int32, uint32, etc) rather
>> than the old-style letter codes; the former is much clearer. The answer
>> to your question might have been immediately apparent had you been
>> using named dtypes.
>> Personally, I'd also prefer people use the "ones([n])" syntax instead
>> of the I-wish-it-were-deprecated-but-it's-too-much-to-hope-for "ones(n)"
>> syntax. T
> Could you elaborate please?
Sure. The general form of the zeros function, and several others, is:
Here 'shape' is a sequence of one sort or another. There's also a
second form that's applicable only to one dimensional arrays:
Where length is an integer. I don't recall if this is a historical
legacy or is intended as a convenience function or a bit of both. Either
way, the result is that there are two ways to spell "give me a 1D array
of zeros with a given length and dtype":
I have two issues with having this second spelling. First, it's one more
thing to remember. Whenever I see the scalar spelling I have to use a
little bit extra of my limited brainpower to remember that it is not in
fact a typo, but is instead a shortcut. The second issue is pedagogical.
If people are initially exposed to the first form, the extension to
multiple dimensions is straightforward. They'll probably guess the
correct way right off the bat, and if not, they'll get it right away
when it's explained. On the other hand, if they are initially exposed to
the second form, the multidimensional form is far from obvious. In
addition, they'll probably spend a long time thinking that the
one-dimensional way is the normal way, but that we have to jump through
weird hoops to get multidimensional arrays to work. That's bad
propaganda for numpy. This all seems like a rather large price to pay to
avoid typing the occasional pair of brackets.
That's my two cents. Just say not to form #2.
...  Yes, I'm neglecting the order parameter; I don't think it
matters for this discussion.
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
More information about the Numpy-discussion