[Numpy-discussion] loadtxt ndmin option

Derek Homeier derek at astro.physik.uni-goettingen.de
Tue May 31 11:52:26 EDT 2011


On 31 May 2011, at 17:33, Bruce Southey wrote:

>>> It certainly would make sense to provide the same functionality for
>>> genfromtxt (which should then be inherited by [nd,ma,rec]fromtxt),  
>>> so
>>> I'd go ahead and file a feature (enhancement) request. I can't  
>>> promise
>>> I can take care of it myself, as I am less familiar with genfromtxt,
>>> but I'd certainly have a look at it.
>> Oh, that shouldn't be too difficult: 'ndmin' tells whether the  
>> array must be squeezed before being returned, right ? You can add  
>> some test at the very end of genfromtxt to check what to do with  
>> the output (whether to squeeze it or not, whether to transpose it  
>> or not)... If you don't mind doing it, I'd be quite grateful (I  
>> don't have time to work on numpy these days, much to my regret).  
>> Don't forget to change the user manual as well...
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> (Different function so different ticket.)
>
> Sure you can change the end of the code but that may hide various
> problem. Unlike loadtxt, genfromtxt has a lot of flexibility  
> especially
> handling missing values and using converter functions. So I think that
> some examples must be provided that can not be handled by providing a
> suitable converter or that require multiple assumptions about input  
> file
> (such as having more than one delimiter).

I think stuff like multiple delimiters should have been dealt with  
before, as the right place to insert the ndmin code (which includes  
the decision to squeeze or not to squeeze as well as to add additional  
dimensions, if required) would be right at the end before the 'unpack'  
switch, or  rather replacing the bit:

     if usemask:
         output = output.view(MaskedArray)
         output._mask = outputmask
     if unpack:
         return output.squeeze().T
     return output.squeeze()

But there it's already not clear to me how to deal with the  
MaskedArray case...

Cheers,
						Derek




More information about the NumPy-Discussion mailing list