[Numpy-discussion] create numerical arrays from strings
chris.barker at noaa.gov
Thu Feb 6 11:42:38 EST 2014
On Thu, Feb 6, 2014 at 5:46 AM, Alan G Isaac <alan.isaac at gmail.com> wrote:
> NumPy matrix construction includes as a convenience feature
> the construction of matrices with a Matlab-like syntax.
> E.g., np.mat('1 2;3 4').
> Is it correct that this syntax is not supported for
> direct (i.e., not using `mat`) ndarray creation?
> You may ask, where would this possibly matter?
> The answer: in the undergraduate classroom.
> Compare np.mat('1 2; 3 4')
> to np.array([[1, 2], [3, 4]])
> for readability and intimidation factor.
> Little things matter when getting started
> with students who lack programming background.
1) so use np.mat !
2) The "right" way involves a few more keystrokes -- is this really a big
"Commas separate elements, each row is enclosed in square brackets"
"whitespace separates elements, semi-colons separate rows."
I'm not sure it's that much harder to understand for a newbie. I'm sure
it is for someone used to MATLAB, but do we really want to encourage folks
to keep their MATLAB habits?
3) Even if it is substantially easier for a newbie, I think we need to be
very careful in teaching to select for "easy to learn first" over "the
right way to do it" -- in general, I think it's more important to establish
good habits and understanding of what's under the covers
than maximizing the ability to type in their first array literal.
4) we really don't want to go down the perl-esque route of "strings
are interpreted as numbers if they happen to be numbers"
IMHO, and all that....
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion