[Numpy-discussion] Short-hand array creation in `numpy.mat` style

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Jul 18 17:31:28 EDT 2014


On Fri, Jul 18, 2014 at 5:04 PM, Joseph Martinot-Lagarde <
joseph.martinot-lagarde at m4x.org> wrote:

> Le 18/07/2014 22:46, Chris Barker a écrit :
> > On Fri, Jul 18, 2014 at 1:15 PM, Joseph Martinot-Lagarde
> > <joseph.martinot-lagarde at m4x.org
> > <mailto:joseph.martinot-lagarde at m4x.org>> wrote:
> >
> >     In addition,
> >     you have to use AltGr on some keyboards to get the brackets.
> >
> >
> > If it's hard to type square brackets -- you're kind of dead in the water
> > with Python anyway -- this is not going to help.
> >
> > -Chris
> >
> Welcome to the azerty world ! ;)
>
> It's not that hard to type, just a bit more involved. My biggest problem
> is that you have to type the opening and closing bracket for each line,
> with a comma in between. It will always be harder and more error prone
> than a single semicolon, whatever the keyboard.
>
> My use case is not teaching but doing quick'n'dirty computations with a
> few values. Sometimes these values are copy-pasted from a space
> separated file, or from a printed array in another console. Having to
> add comas and bracket makes simple computations less easy. That's why I
> often use Octave for these.
>

my copy paste approaches for almost quick'n'dirty (no semicolons):

given:

a b c

1 2 3

4 5 6

7 8 9


(select & Ctrl-C)


>>> pandas.read_clipboard(sep=' ')

   a  b  c

0  1  2  3

1  4  5  6

2  7  8  9


>>> np.asarray(pandas.read_clipboard())

array([[1, 2, 3],

       [4, 5, 6],

       [7, 8, 9]], dtype=int64)


>>> pandas.read_clipboard().values

array([[1, 2, 3],

       [4, 5, 6],

       [7, 8, 9]], dtype=int64)


arr = np.array('''\

1 2 3

4 5 6

7 8 9'''.split(), float).reshape(-1, 3)


the last is not so quick and dirty but reusable and reused.


Josef





>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140718/8e32090c/attachment.html>


More information about the NumPy-Discussion mailing list