[Numpy-discussion] create numerical arrays from strings

Stéfan van der Walt stefan at sun.ac.za
Thu Feb 6 09:04:35 EST 2014


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




More information about the NumPy-Discussion mailing list