From: Colin J. W. <cj...@sy...> - 2006-11-06 20:10:49
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> <br> <br> Tim Hochberg wrote: <blockquote cite="mid...@ie..." type="cite"> <pre wrap="">Colin J. Williams wrote: </pre> <blockquote type="cite"> <pre wrap="">Tim Hochberg wrote: [snip] </pre> <blockquote type="cite"> <pre wrap="">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. </pre> </blockquote> <pre wrap="">+1 </pre> <blockquote type="cite"> <pre wrap=""> 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 </pre> </blockquote> <pre wrap="">Could you elaborate please? </pre> </blockquote> <pre wrap=""><!---->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. </pre> </blockquote> Tim,<br> <br> Many thanks. In general, there is sense in the Python dictum about having one<br> way to do things. Although, in this case [length] vs length for one dimension doesn't<br> exercise me greatly. I would be a bit more concerned about synonyms.<br> <br> Nobody has proposed using English yet - zeroes.<br> <br> Colin W.<br> </body> </html> |