Re: [Numpy-discussion] loadtxt issues

2009-02-10 Thread Brent Pedersen
On Tue, Feb 10, 2009 at 9:40 PM, A B wrote: > Hi, > > How do I write a loadtxt command to read in the following file and > store each data point as the appropriate data type: > > 12|h|34.5|44.5 > 14552|bbb|34.5|42.5 > > Do the strings have to be read in separately from the numbers? > > Why would a

[Numpy-discussion] loadtxt issues

2009-02-10 Thread A B
Hi, How do I write a loadtxt command to read in the following file and store each data point as the appropriate data type: 12|h|34.5|44.5 14552|bbb|34.5|42.5 Do the strings have to be read in separately from the numbers? Why would anyone use 'S10' instead of 'string'? dt = {'names': ('gender',

Re: [Numpy-discussion] Loadtxt .bz2 support

2008-10-22 Thread Ryan May
Charles R Harris wrote: > On Tue, Oct 21, 2008 at 1:30 PM, Ryan May <[EMAIL PROTECTED]> wrote: > >> Hi, >> >> I noticed numpy.loadtxt has support for gzipped text files, but not for >> bz2'd files. Here's a 3 line patch to add bzip2 support to loadtxt. >> >> Ryan >> >> -- >> Ryan May >> Graduate

Re: [Numpy-discussion] Loadtxt .bz2 support

2008-10-21 Thread Charles R Harris
On Tue, Oct 21, 2008 at 1:30 PM, Ryan May <[EMAIL PROTECTED]> wrote: > Hi, > > I noticed numpy.loadtxt has support for gzipped text files, but not for > bz2'd files. Here's a 3 line patch to add bzip2 support to loadtxt. > > Ryan > > -- > Ryan May > Graduate Research Assistant > School of Meteoro

[Numpy-discussion] Loadtxt .bz2 support

2008-10-21 Thread Ryan May
Hi, I noticed numpy.loadtxt has support for gzipped text files, but not for bz2'd files. Here's a 3 line patch to add bzip2 support to loadtxt. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma Index: numpy/lib/io.py =

Re: [Numpy-discussion] loadtxt

2008-10-02 Thread Stéfan van der Walt
2008/10/2 Francesc Alted <[EMAIL PROTECTED]>: >> how can I load ASCII data if the file contains characters >> instead of floats > > You would need to specify the length of your strings. Try with > dtype="SN", where N is the expected length of the strings. Other options include: - using converter

Re: [Numpy-discussion] loadtxt

2008-10-02 Thread Francesc Alted
A Thursday 02 October 2008, Nils Wagner escrigué: > Hi all, > > how can I load ASCII data if the file contains characters > instead of floats > > Traceback (most recent call last): >File "test_csv.py", line 2, in > A = loadtxt('ca6_sets.csv',dtype=char ,delimiter=';') > NameError: name 'c

[Numpy-discussion] loadtxt

2008-10-02 Thread Nils Wagner
Hi all, how can I load ASCII data if the file contains characters instead of floats Traceback (most recent call last): File "test_csv.py", line 2, in A = loadtxt('ca6_sets.csv',dtype=char ,delimiter=';') NameError: name 'char' is not defined Nils _

Re: [Numpy-discussion] loadtxt error

2008-09-25 Thread Stéfan van der Walt
2008/9/24 frank wang <[EMAIL PROTECTED]>: > Thank you very much for all of you. I have downloaded the binary version > 1.2rc and it fixed the problem. > > My special thanks to the person who created the window binary version for > users who do not know or do not have the capacity to build the numpy

Re: [Numpy-discussion] loadtxt error

2008-09-24 Thread frank wang
Sep 2008 17:10:45 +0200> From: [EMAIL PROTECTED]> To: numpy-discussion@scipy.org> Subject: Re: [Numpy-discussion] loadtxt error> > 2008/9/24 Joshua Lippai <[EMAIL PROTECTED]>:> > And the version would be displayed on screen. Bear in mind that unlike> > the release, w

Re: [Numpy-discussion] loadtxt error

2008-09-24 Thread Stéfan van der Walt
2008/9/24 Joshua Lippai <[EMAIL PROTECTED]>: > And the version would be displayed on screen. Bear in mind that unlike > the release, which installs via an installer file you double click, > you will have to compile numpy from the downloaded source code > yourself. Detailed instructions for doing th

Re: [Numpy-discussion] loadtxt error

2008-09-24 Thread David Huard
i = usecols.find(i) > > 340 converters[i] = conv > > 341 > > AttributeError: 'list' object has no attribute 'find' > >> c:\python25\lib\site-packages\numpy\lib\io.py(339)loadtxt() > > 338 if usecols: > > -

Re: [Numpy-discussion] loadtxt error

2008-09-23 Thread Joshua Lippai
object has no attribute 'find' >> c:\python25\lib\site-packages\numpy\lib\io.py(339)loadtxt() > 338 if usecols: > --> 339 i = usecols.find(i) > 340 converters[i] = conv > > > Thanks > > Frank > >> From: [EMAIL PROTEC

Re: [Numpy-discussion] loadtxt error

2008-09-23 Thread frank wang
e-packages\numpy\lib\io.py(339)loadtxt()338 if usecols:--> 339 i = usecols.find(i)340 converters[i] = conv Thanks Frank> From: [EMAIL PROTECTED]> To: numpy-discussion@scipy.org> Date: Mon, 22 Sep 2008 20:10:11 -0400> Subject: Re: [Numpy-discussion] lo

Re: [Numpy-discussion] loadtxt error

2008-09-23 Thread frank wang
My numpy version is numpy-1.1.1-win32-superpack-python2.5.exe. It is the newest release. By the way, in Python, how can I check numpy version? Thanks Frank Date: Tue, 23 Sep 2008 08:42:00 -0400From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: [Numpy-discussion] loadtxt error This bug has

Re: [Numpy-discussion] loadtxt error

2008-09-23 Thread David Huard
This bug has been fixed in the trunk a couple of weeks ago. Cheers, David On Mon, Sep 22, 2008 at 8:10 PM, Pierre GM <[EMAIL PROTECTED]> wrote: > On Monday 22 September 2008 19:56:47 frank wang wrote: > > This error is caused that the usecols is a tuple and it does not have > find > > command.

Re: [Numpy-discussion] loadtxt error

2008-09-22 Thread Pierre GM
On Monday 22 September 2008 19:56:47 frank wang wrote: > This error is caused that the usecols is a tuple and it does not have find > command. I do not know how to fix this problem. Try to use a list instead of a tuple as a quick-fix. Anyway, Frank, you should try to give us the version of numpy y

Re: [Numpy-discussion] loadtxt error

2008-09-22 Thread frank wang
This error is caused that the usecols is a tuple and it does not have find command. I do not know how to fix this problem. Thanks Frank From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Mon, 22 Sep 2008 15:27:13 -0600Subject: Re: [Numpy-discussion] loadtxt error Hi, Stefan, Thanks for your

Re: [Numpy-discussion] loadtxt error

2008-09-22 Thread frank wang
= conv This command is the same as yours. I do not know why it is working for you.> Date: Mon, 22 Sep 2008 22:13:18 +0200> From: [EMAIL PROTECTED]> To: numpy-discussion@scipy.org> Subject: Re: [Numpy-discussion] loadtxt error> > 2008/9/22 frank wang <[EMAIL PROTEC

Re: [Numpy-discussion] loadtxt error

2008-09-22 Thread Stéfan van der Walt
2008/9/22 frank wang <[EMAIL PROTECTED]>: > It will load an array has two columns. However, I only want to load one > column to save the memory. If I type > > fid=loadtxt('filename.csv',comments='"',dtype='|S4',converters={0:lambda > s:int(s,16)},usecols=(1,)) You are specifying a converter that w

[Numpy-discussion] loadtxt error

2008-09-22 Thread frank wang
Hi, All, I am struggling to make the loadtxt works. In my file, I have several colunms of data, say I have two. When I use the following command to load the data, fid=loadtxt('filename.csv',comments='"',dtype='|S4',converters={0:lambda s:int(s,16)}) It will load an array has two columns.

[Numpy-discussion] loadtxt improvement

2008-09-15 Thread Neil
I'd like to add a way for loadtxt to infer a dtype from the data it reads in. Record arrays/structured arrays are the best thing ever, and ideally I'd like to read in a csv-style file into a structured array in one easy step. loadtxt almost does this - if I know the number and type of fields befo

Re: [Numpy-discussion] loadtxt and usecols

2008-07-14 Thread Zbyszek Szmek
> data = loadtxt('18B180.dat', skiprows = 1, usecols = xrange(1,46)) On Sat, Jul 12, 2008 at 04:35:20PM +0200, Lorenzo Bolla wrote: > why not using: or data = loadtxt('18B180.dat', skiprows=1, unpack=True)[1:] > > obviously, you need to know how many columns you have. Or not, if you don't mind th

Re: [Numpy-discussion] loadtxt and N/A

2008-07-13 Thread Lorenzo Bolla
you can use the 'converters' keyword in numpy.loadtxt. first define a function to convert a string in a float, that can handle your 'N/A' entries: def converter(x): if x == 'N/A': return numpy.nan else: return float(x) then use: >>> numpy.loadtxt('test.dat', converters={1

[Numpy-discussion] loadtxt and N/A

2008-07-13 Thread Bryan Fodness
I am using loadtxt and I have missing values that are show up as N/A. I get a, ValueError: invalid literal for float(): N/A Is there a way to ignore these? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/l

Re: [Numpy-discussion] loadtxt and usecols

2008-07-12 Thread Lorenzo Bolla
why not using: data = loadtxt('18B180.dat', skiprows = 1, usecols = xrange(1,46)) obviously, you need to know how many columns you have. hth, L. On Sat, Jul 12, 2008 at 10:07:06AM -0400, Bryan Fodness wrote: > i would like to load my data without knowing the length, i have explicitly > stated the

[Numpy-discussion] loadtxt and usecols

2008-07-12 Thread Bryan Fodness
i would like to load my data without knowing the length, i have explicitly stated the rows data = loadtxt('18B180.dat', skiprows = 1, usecols = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45)) and would like to use some

Re: [Numpy-discussion] loadtxt and missing values

2008-03-06 Thread Keith Goodman
On Thu, Mar 6, 2008 at 1:12 PM, Sean Arms <[EMAIL PROTECTED]> wrote: > > Keith Goodman wrote: > > On Thu, Mar 6, 2008 at 12:36 PM, <[EMAIL PROTECTED]> wrote: > > > > > >> Proposed solution: > >> - > >> > >> It's probably not the best way (noob, that's me), but thi

Re: [Numpy-discussion] loadtxt and missing values

2008-03-06 Thread Sean Arms
Keith Goodman wrote: > On Thu, Mar 6, 2008 at 12:36 PM, <[EMAIL PROTECTED]> wrote: > > >> Proposed solution: >> - >> >> It's probably not the best way (noob, that's me), but this situation could >> be fixed by: >> >> 1) add a fill keyword to loadtxt such that >> >>

Re: [Numpy-discussion] loadtxt and missing values

2008-03-06 Thread Keith Goodman
On Thu, Mar 6, 2008 at 12:36 PM, <[EMAIL PROTECTED]> wrote: > Proposed solution: > - > > It's probably not the best way (noob, that's me), but this situation could > be fixed by: > > 1) add a fill keyword to loadtxt such that > > def loadtxt(...,fill=-999): > > 2) a

[Numpy-discussion] loadtxt and missing values

2008-03-06 Thread caver_sean
Greetings! I'm relatively new to numpy (and python in general), and so far I have been very pleased! I've been writing an atmospheric boundary-layer observation analysis package to use for my PhD research and I have ran into an issue with the loadtxt function (as an aside, our dataloggers outp

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-28 Thread Christopher Barker
Lisandro Dalcin wrote: > On 2/27/08, Travis E. Oliphant <[EMAIL PROTECTED]> wrote: >> Did this discussion resolve with a fix that can go in before 1.0.5 is >> released? > > I believe the answer is yes, but we have to choose: > > 1- Use the regepx based solution of David. A good idea, but a feat

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-28 Thread Lisandro Dalcin
On 2/27/08, Travis E. Oliphant <[EMAIL PROTECTED]> wrote: > Did this discussion resolve with a fix that can go in before 1.0.5 is > released? I believe the answer is yes, but we have to choose: 1- Use the regepx based solution of David. 2- Move to use 'index' instead of 'find' as proposed by Al

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Robert Kern
On Thu, Feb 28, 2008 at 12:12 AM, Alan G Isaac <[EMAIL PROTECTED]> wrote: > > On Wed, 27 Feb 2008, Robert Kern apparently wrote: > >> Fixed in r4827. > > > > > On Wed, Feb 27, 2008 at 6:31 PM, Christopher Barker wrote: > >> For the record, this is the fixed version: > >> comment_start =

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Alan G Isaac
> On Wed, 27 Feb 2008, Robert Kern apparently wrote: >> Fixed in r4827. > On Wed, Feb 27, 2008 at 6:31 PM, Christopher Barker wrote: >> For the record, this is the fixed version: >> comment_start = line.find(comments) >> if comment_start > 0: >> line = line[:comments

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Robert Kern
On Wed, Feb 27, 2008 at 6:31 PM, Christopher Barker <[EMAIL PROTECTED]> wrote: > Robert Kern wrote: > > Fixed in r4827. > > Thanks Robert. For the record, this is the fixed version: > > comment_start = line.find(comments) > if comment_start > 0: > line = line[:commen

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Christopher Barker
Robert Kern wrote: > Fixed in r4827. Thanks Robert. For the record, this is the fixed version: comment_start = line.find(comments) if comment_start > 0: line = line[:comments_start].strip() else: line = line.strip() Just as a matter of interest

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Robert Kern
On Wed, Feb 27, 2008 at 4:04 PM, Travis E. Oliphant <[EMAIL PROTECTED]> wrote: > Did this discussion resolve with a fix that can go in before 1.0.5 is > released? Fixed in r4827. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Travis E. Oliphant
Lisandro Dalcin wrote: > Well, after all that said, I'm also fine with either approach. Anyway, > I would say that my personal preference is for the one using > 'str.index', as it is the simplest one regarding the old code. > > Like Christopher, I rarelly (never?) use 'loadtxt'. But this issue > ma

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Lisandro Dalcin
Well, after all that said, I'm also fine with either approach. Anyway, I would say that my personal preference is for the one using 'str.index', as it is the simplest one regarding the old code. Like Christopher, I rarelly (never?) use 'loadtxt'. But this issue made a coworker to get crazy (he is

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Christopher Barker
David Huard wrote: > The advantage of using regular expressions is that in this case it gives > you some flexibility that wasn't there before. For instance, if for any > reason there are two type of characters that coexist in the file to mark > comments, using > pattern = re.compile(comments) >

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Christopher Barker
Alan Isaac wrote: Use index instead? yup, that'll work. enclosed is another test file, with that and one using string.split(comments) instead. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R(206) 526-6959 voice 7600 Sand Point Wa

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Alan Isaac
On Wed, 27 Feb 2008, Christopher Barker wrote: > The issue here is a result of what I consider a wart in python's string > methods -- string.find() returns a valid index( -1 ) when > it fails to find anything. Use index instead? Cheers, Alan Isaac __

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread David Huard
Hi Christopher, The advantage of using regular expressions is that in this case it gives you some flexibility that wasn't there before. For instance, if for any reason there are two type of characters that coexist in the file to mark comments, using pattern = re.compile(comments) for i,line in en

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread Christopher Barker
David Huard wrote: Would everyone be satisfied with a solution using regular expressions ? Maybe it's because regular expressions make me itch, but I think it's overkill for this. The issue here is a result of what I consider a wart in python's string methods -- string.find() returns a vali

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread David Huard
Lisandro, When you have some time, could you check this patch solves your problem (and does not introduce new ones) ? David Index: numpy/lib/io.py === --- numpy/lib/io.py (revision 4824) +++ numpy/lib/io.py (working copy) @

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-27 Thread David Huard
I can look at it. Would everyone be satisfied with a solution using regular expressions ? That is, looking for the following pattern: pattern = re.compile(r""" ^\s* # leading white space (.*) # Data %s? # Zero or one comment character (.*) # Comments \s*$ # Trailing white spa

Re: [Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-26 Thread Alan G Isaac
On Tue, 26 Feb 2008, Lisandro Dalcin apparently wrote: > I believe the current 'loadtxt' function is broken I agree: http://projects.scipy.org/pipermail/numpy-discussion/2007-November/030057.html> Cheers, Alan Isaac ___ Numpy-discussion mailing list

[Numpy-discussion] loadtxt broken if file does not end in newline

2008-02-26 Thread Lisandro Dalcin
Dear all, I believe the current 'loadtxt' function is broken if file does not end in newline. The problem is at the last line of this fragment: for i,line in enumerate(fh): if ihttp://projects.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] loadtxt bug?

2007-11-23 Thread Alan G Isaac
> On Fri, Nov 23, 2007 at 07:58:13AM -0500, Alan G Isaac wrote: >> Specifically, is it not the case that the last line of >> a text file is not guaranteed to have a terminator? Does >> this not raise the possibility that a digit will be >> clipped from the last line? On Fri, 23 Nov 2007, Gae

Re: [Numpy-discussion] loadtxt bug?

2007-11-23 Thread Gael Varoquaux
On Fri, Nov 23, 2007 at 07:58:13AM -0500, Alan G Isaac wrote: > > On Thu, Nov 22, 2007 at 11:14:07PM -0500, Alan G Isaac wrote: > >> In numpy.core.numeric.py you will find loadtxt, which uses > >> the following:: > >> line = line[:line.find(comments)].strip() > On Fri, 23 Nov 2007, Gael

Re: [Numpy-discussion] loadtxt bug?

2007-11-23 Thread Alan G Isaac
> On Thu, Nov 22, 2007 at 11:14:07PM -0500, Alan G Isaac wrote: >> In numpy.core.numeric.py you will find loadtxt, which uses >> the following:: >> line = line[:line.find(comments)].strip() On Fri, 23 Nov 2007, Gael Varoquaux apparently wrote: > Unless you are sure that line always ends

Re: [Numpy-discussion] loadtxt bug?

2007-11-22 Thread Gael Varoquaux
On Thu, Nov 22, 2007 at 11:14:07PM -0500, Alan G Isaac wrote: > In numpy.core.numeric.py you will find loadtxt, which uses > the following:: > line = line[:line.find(comments)].strip() > I believe there is a bug here (when a line has no comment). > To illustrate:: > >>> line = "12345

[Numpy-discussion] loadtxt bug?

2007-11-22 Thread Alan G Isaac
In numpy.core.numeric.py you will find loadtxt, which uses the following:: line = line[:line.find(comments)].strip() I believe there is a bug here (when a line has no comment). To illustrate:: >>> line = "12345" >>> comments = "#" >>> line[:line.find(comments)] '1234' So

<    1   2