On 18 Jun 2011, at 04:48, gary ruben wrote:
Thanks guys - I'm happy with the solution for now. FYI, Derek's
suggestion doesn't work in numpy 1.5.1 either.
For any developers following this thread, I think this might be a nice
use case for genfromtxt to handle in future.
Numpy 1.6.0 and above
If I understand correctly, your error is that you convert only the second
column, because your converters dictionary contains a single key (1).
If you have it contain keys from 0 to 3 associated to the same function, it
should work.
-=- Olivier
2011/6/17 gary ruben gru...@bigpond.net.au
I'm
Thanks Olivier,
Your suggestion gets me a little closer to what I want, but doesn't
quite work. Replacing the conversion with
c = lambda x:np.cast[np.complex64](complex(*eval(x)))
b = np.genfromtxt(a,converters={0:c, 1:c, 2:c,
3:c},dtype=None,delimiter=18,usecols=range(4))
produces
On 06/17/2011 08:22 AM, gary ruben wrote:
Thanks Olivier,
Your suggestion gets me a little closer to what I want, but doesn't
quite work. Replacing the conversion with
c = lambda x:np.cast[np.complex64](complex(*eval(x)))
b = np.genfromtxt(a,converters={0:c, 1:c, 2:c,
2011/6/17 Bruce Southey bsout...@gmail.com
On 06/17/2011 08:22 AM, gary ruben wrote:
Thanks Olivier,
Your suggestion gets me a little closer to what I want, but doesn't
quite work. Replacing the conversion with
c = lambda x:np.cast[np.complex64](complex(*eval(x)))
b =
On 06/17/2011 08:51 AM, Olivier Delalleau wrote:
2011/6/17 Bruce Southey bsout...@gmail.com mailto:bsout...@gmail.com
On 06/17/2011 08:22 AM, gary ruben wrote:
Thanks Olivier,
Your suggestion gets me a little closer to what I want, but doesn't
quite work. Replacing the
Thanks for the hints Olivier and Bruce. Based on them, the following
is a working solution, although I still have that itchy sense that genfromtxt
should be able to do it directly.
import numpy as np
from StringIO import StringIO
a = StringIO('''\
(-3.9700,-5.0400) (-1.1318,-2.5693)
Hi Gary,
On 17.06.2011, at 5:39PM, gary ruben wrote:
Thanks for the hints Olivier and Bruce. Based on them, the following
is a working solution, although I still have that itchy sense that genfromtxt
should be able to do it directly.
import numpy as np
from StringIO import StringIO
a =
2011/6/17 Derek Homeier de...@astro.physik.uni-goettingen.de
Hi Gary,
On 17.06.2011, at 5:39PM, gary ruben wrote:
Thanks for the hints Olivier and Bruce. Based on them, the following
is a working solution, although I still have that itchy sense that
genfromtxt
should be able to do it
On 17.06.2011, at 11:01PM, Olivier Delalleau wrote:
You were just overdoing it by already creating an array with the converter,
this apparently caused genfromtxt to create a structured array from the
input (which could be converted back to an ndarray, but that can prove
tricky as well) -
Thanks guys - I'm happy with the solution for now. FYI, Derek's
suggestion doesn't work in numpy 1.5.1 either.
For any developers following this thread, I think this might be a nice
use case for genfromtxt to handle in future.
As a corollary of this problem, I wonder whether there's a
For the hardcoded part, you can easily read the first line of your file and
split it with the same delimiter to know the number of columns.
It's sure it'd be best to be able to be able to skip this part, but you
don't need to hardcode this number into your code at least.
Something like:
n_cols =
I'm trying to read a file containing data formatted as in the
following example using genfromtxt and I'm doing something wrong. It
almost works. Can someone point out my error, or suggest a simpler
solution to the ugly converter function? I thought I'd leave in the
commented-out line for future
13 matches
Mail list logo