Tim Hochberg wrote:
Colin J. Williams wrote:
Tim Hochberg wrote:
[snip]
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.
+1
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
-tim
Could you elaborate please?
Sure. The general form of the zeros function, and several others[1], is:
zeros(shape, dtype)
Here 'shape' is a sequence of one sort or another. There's also a
second form that's applicable only to one dimensional arrays:
zeros(length, dtype)
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":
zeros([length], dtype)
and
zeros(length, 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.
-tim
... [1] Yes, I'm neglecting the order parameter; I don't think it
matters for this discussion.
Tim,
Many thanks. In general, there is sense in the Python dictum about
having one
way to do things. Although, in this case [length] vs length for one
dimension doesn't
exercise me greatly. I would be a bit more concerned about synonyms.
Nobody has proposed using English yet - zeroes.
Colin W.
|
-------------------------------------------------------------------------
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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion