NumPy matrix construction includes as a convenience feature the construction of matrices with a Matlablike 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. Thanks, Alan Isaac
Hi Alan On Thu, 06 Feb 2014 08:46:49 0500, Alan G Isaac wrote:
You may ask, where would this possibly matter? The answer: in the undergraduate classroom.
As a lecturer, I understand where you are coming from, but I don't think we can ultimately make API decisions based on teachability. The ndarray constructor already has behavior defined for strings: np.array('1 2 3; 4 5 6') array('1 2 3; 4 5 6', dtype='S12') So we can't easily change that now. The best is probably to write a small utility library for your students that help them to easily construct arrays. Also, if you teach them inside an IPython Notebook, they can easily type np.ndarray([[1, 2], [3, 4]]) which is quite readable and makes use of standard Python objects. Regards Stéfan
On Thu, Feb 6, 2014 at 5:46 AM, Alan G Isaac
NumPy matrix construction includes as a convenience feature the construction of matrices with a Matlablike 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 deal? "Commas separate elements, each row is enclosed in square brackets" vs: "whitespace separates elements, semicolons 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 perlesque route of "strings are interpreted as numbers if they happen to be numbers" IMHO, and all that.... CHB  Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 5266959 voice 7600 Sand Point Way NE (206) 5266329 fax Seattle, WA 98115 (206) 5266317 main reception Chris.Barker@noaa.gov
At 05:46 AM 2/6/2014, Alan G Isaac wrote:
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.
my $.02:
'1 2; 3 4' is a nonobvious and nonintuitive way to describe a 2D array or matrix  and try explaining later that the values are actually stored in memory as 1,3,2,4 and why and watch the freshman chins drop...
np.array([[1,2], ... [3,4]]) ... array([[1, 2], [3, 4]]) Why use both significant whitespace and punctuation to separate elements?
I've billed many months rewriting old Matlab code into Python  please don't saddle future engineers with a closed, nonobjective, expensive product based on FORTRAN and written in C that breaks old code with every release. </rant> There are so many fine, easy tutorials like http://wiki.scipy.org/Tentative_NumPy_Tutorial http://www.loria.fr/~rougier/teaching/matplotlib/  Ray
participants (4)

Alan G Isaac

Chris Barker

RayS

Stéfan van der Walt