Re: [Numpy-discussion] String manipulation

2009-07-21 Thread David Goldsmith
--- On Tue, 7/21/09, Christopher Barker wrote: > but now when I try to split it up: > > In [38]: a = a.view(dtype='S13') > > I get: > > ValueError: new type not compatible with array. > > Shouldn't that work? > > -Chris Submit an enhancement ticket. ;-) DG ___

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Christopher Barker
David Goldsmith wrote: > Hi, Chris. Look at this, _I'm_ answering one of _your_ questions > (correctly, I hope): maybe ;-) > --- On Tue, 7/21/09, Christopher Barker > wrote: >> I don't see why: >> >> np.array('a string', dtype='S1') >> >> results in a length (1,) array, for instance. > Well,

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Darren Dale
On Tue, Jul 21, 2009 at 2:41 PM, Matthew Brett wrote: > Hi, > >>> I'm the person who removed the reference to thread-safeness in the >>> numpy version of the subclassing docs.   I remember at the time going >>> through all the email discussions that led up to the thread-safeness >>> question, and c

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Pierre GM
On Jul 21, 2009, at 2:23 PM, Darren Dale wrote: > >> Without access to your code, I'm likely to speak beyond myself here >> (could you send me a link to the latest version ?), but if you need >> to >> rescale the units, make sure it's done in __array_finalize__ as well, >> with something like >>

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Matthew Brett
Hi, >> I'm the person who removed the reference to thread-safeness in the >> numpy version of the subclassing docs.   I remember at the time going >> through all the email discussions that led up to the thread-safeness >> question, and concluding (in discussion with Travis O and others) that >> th

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Darren Dale
Hi Matthew, On Tue, Jul 21, 2009 at 1:37 PM, Matthew Brett wrote: > Hi, > >> The words of caution were intended to remind that setting the value >> of  new array attributes in __new__ only could lead to problems, as >> it's possible to transform a ndarray into a subclass with a view (that >> is, c

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Darren Dale
On Tue, Jul 21, 2009 at 1:26 PM, Pierre GM wrote: > > On Jul 21, 2009, at 10:58 AM, Darren Dale wrote: > >> http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#simple-example-adding-an-extra-attribute-to-ndarray >> includes an example where an instance attribute is set in __new__ . >> Howe

Re: [Numpy-discussion] suggestion for generalizing numpy functions

2009-07-21 Thread Robert Kern
On Tue, Jul 21, 2009 at 09:11, Darren Dale wrote: > (off topic: it would be nice if numpy had a mechanism in place for > merge requests and code reviews. I've been following bzr-dev for a > while now and their development model is pretty impressive.) You can use Rietveld. numpy is already a regist

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Matthew Brett
Hi, > The words of caution were intended to remind that setting the value > of  new array attributes in __new__ only could lead to problems, as > it's possible to transform a ndarray into a subclass with a view (that > is, calling __array_finalize__ without calling __new__). In the Simple > Exampl

Re: [Numpy-discussion] proper use of __new__

2009-07-21 Thread Pierre GM
On Jul 21, 2009, at 10:58 AM, Darren Dale wrote: > http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#simple-example-adding-an-extra-attribute-to-ndarray > includes an example where an instance attribute is set in __new__ . > However, there is a warning at http://www.scipy.org/Subclasse

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread David Goldsmith
Hi, Chris. Look at this, _I'm_ answering one of _your_ questions (correctly, I hope): --- On Tue, 7/21/09, Christopher Barker wrote: > I don't see why: > > np.array('a string', dtype='S1') > > results in a length (1,) array, for instance. > > Actually, I think I do -- numpy is treating the

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Christopher Barker
Pierre GM wrote: > On Jul 20, 2009, at 3:44 PM, Christopher Barker wrote: >> ... >> Is there a cleaner way to do this? > Yes. np.lib._iotools.LineSplitter and/or np.genfromtxt Great, thanks -- though the underscore in _iotools implies that this isn't supposed to be general purpose tools. Also,

[Numpy-discussion] proper use of __new__

2009-07-21 Thread Darren Dale
http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#simple-example-adding-an-extra-attribute-to-ndarray includes an example where an instance attribute is set in __new__ . However, there is a warning at http://www.scipy.org/Subclasses: - Some words of caution The definition in the __

Re: [Numpy-discussion] suggestion for generalizing numpy functions

2009-07-21 Thread Darren Dale
On Tue, Jul 21, 2009 at 7:44 AM, Darren Dale wrote: > 2009/7/20 Stéfan van der Walt : >> Hi Chuck >> >> 2009/7/17 Charles R Harris : >>> PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos) >>> Return value: Borrowed reference. >>> Return the object at position pos in the tuple pointed to by p. I

Re: [Numpy-discussion] suggestion for generalizing numpy functions

2009-07-21 Thread Darren Dale
2009/7/20 Stéfan van der Walt : > Hi Chuck > > 2009/7/17 Charles R Harris : >> PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos) >> Return value: Borrowed reference. >> Return the object at position pos in the tuple pointed to by p. If pos is >> out of bounds, return NULL and sets an IndexErro

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Pierre GM
On Jul 21, 2009, at 3:16 AM, Nils Wagner wrote: >> >> Er, there's already something like that: >> np.lib._iotools.LineSplitter > > Great. I didn't know about that. > > Your examples are very useful. > > IMHO the examples should be added to > > http://www.scipy.org/Cookbook/InputOutput > > to attra

Re: [Numpy-discussion] String manipulation

2009-07-21 Thread Nils Wagner
On Tue, 21 Jul 2009 02:56:28 -0400 Pierre GM wrote: > > On Jul 21, 2009, at 2:42 AM, Nils Wagner wrote: >> >> Fixed-length fields are quite common e.g. in the area of >> Finite Element pre/postprocessing. >> Therefore It would be nice to have a function like >> line2array in numpy. >> Comments