Re: [Numpy-discussion] ticket 1562 on loadtxt (was Re: Numpy 2.0 schedule)

2011-03-02 Thread Benjamin Root
On Mon, Feb 28, 2011 at 11:45 AM, Bruce Southey bsout...@gmail.com wrote:

  On 02/28/2011 09:47 AM, Benjamin Root wrote:

 On Mon, Feb 28, 2011 at 9:25 AM, Bruce Southey bsout...@gmail.com wrote:

 On 02/28/2011 09:02 AM, Benjamin Root wrote:
 [snip]
 
 
  So, is there still no hope in addressing this old bug report of mine?
 
  http://projects.scipy.org/numpy/ticket/1562
 
  Ben Root
 
  I think you need to add more details to this. So do you have an example
 of the problem that includes code and expected output?

 Perhaps genfromtxt is probably more appropriate than loadtxt for what
 you want:

 from StringIO import StringIO
 import numpy as np
 t = StringIO(1,1.3,abcde\n2,2.3,wxyz\n1\n3,3.3,mnop)
 data = np.genfromtxt(t,
 [('myint','i8'),('myfloat','f8'),('mystring','S5')], names =
 ['myint','myfloat','mystring'], delimiter=,, invalid_raise=False)
 print 'Bad data raise\n',data

 This gives the output that skips the incomplete 3rd line:

 /usr/lib64/python2.7/site-packages/numpy/lib/npyio.py:1507:
 ConversionWarning: Some errors were detected !
 Line #3 (got 1 columns instead of 3)
   warnings.warn(errmsg, ConversionWarning)
 Bad data raise
 [(1, 1.3, 'abcde') (2, 2.3, 'wxyz') (3, 3.3, 'mnop')]


 Bruce


 Bruce,

 I think you mis-understood the problem I was reporting.

 Probably - which is why I asked for more details.

  You can find the discussion thread here:

 http://www.mail-archive.com/numpy-discussion@scipy.org/msg26235.html

 I have proposed that at the very least, an example of this problem is added
 to the documentation of loadtxt so that users know to be aware of this
 possibility.

 I did not connect the ticket to that email thread. Removing the structured
 array part of your email, I think essentially the argument is which should
 be the output of:
 np.loadtxt(StringIO(89.23))
 np.arange(5)[1]

 These return an 0-d array and an rather old argument about that (which may
 address the other part of the ticket). Really I see this behavior as
 standard so you add an example to the documentation to reflect that.


I agree that this behavior has become standard, and, by-and-large,
desirable.  It just comes with this sneaky pitfall when encountering
single-line files.  Therefore, I have a couple of suggestions that I would
find suitable for resolution of this report.  I will leave it up to the
developers to decide which course to pursue.

1. Add a mindims parameter that would default to None (for current
behavior).  The caller can specify the minimum number of dimensions the
resulting array should have and then call some sort of function like
np.atleast_nd() (I know it doesn't exists, but such a function might be
useful).  The documentation for this keyword param would allude to the
rational for its use.

2. Keep the current behavior, but possibly not for when a dtype is
specified.  Given that the squeeze() was meant for addressing the situation
where the data structure is not known a priori, squeezing a known dtype
seems to go against this rationale.

3. Keep the current behavior, but add some documentation for loadtxt() that
illustrates the problem and shows the usage of a function like
np.atleast_2d().  I would be willing to write up such an example.



  In addition, loadtxt fails on empty files even when provided with a
 dtype.  I believe genfromtxt also fails as well in this case.

 Ben Root

   Errors on empty files probably should be a new bug report as that was
 not in the ticket.


Done:  http://projects.scipy.org/numpy/ticket/1752

Thanks,
Ben Root
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] (no subject)

2011-03-02 Thread Alex Ter-Sarkissov
hi, the question is probably very silly, but can't get my head around it

Say I have an NxM numerical array. What I want is to obtain the row and
column number of the smallest value(kinda like find command in Matlab). I
use something like where(min(array_name)), but keep getting the error
message. I'd be glad if any1 could have any suggestions in this regard.

cheers,

Alex
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] (no subject)

2011-03-02 Thread Skipper Seabold
On Wed, Mar 2, 2011 at 5:25 PM, Alex Ter-Sarkissov ater1...@gmail.com wrote:
 hi, the question is probably very silly, but can't get my head around it

 Say I have an NxM numerical array. What I want is to obtain the row and
 column number of the smallest value(kinda like find command in Matlab). I
 use something like where(min(array_name)), but keep getting the error
 message. I'd be glad if any1 could have any suggestions in this regard.


In [1]: import numpy as np

In [2]: A = np.random.randn(10,10)

In [3]: np.where(A==np.min(A))
Out[3]: (array([5]), array([3]))

Skipper
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] (no subject)

2011-03-02 Thread Robert Kern
On Wed, Mar 2, 2011 at 16:25, Alex Ter-Sarkissov ater1...@gmail.com wrote:
 hi, the question is probably very silly, but can't get my head around it

 Say I have an NxM numerical array. What I want is to obtain the row and
 column number of the smallest value(kinda like find command in Matlab). I
 use something like where(min(array_name)), but keep getting the error
 message. I'd be glad if any1 could have any suggestions in this regard.

[~]
|15 A = np.random.random([3,5])

[~]
|16 i = A.min(axis=1).argmin()

[~]
|17 j = A.min(axis=0).argmin()

[~]
|18 A[i,j]
0.0065380564732848701

[~]
|19 A.min()
0.0065380564732848701

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth.
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] ticket #1619

2011-03-02 Thread Charles R Harris
I think that this ticket can benefit from some discussion on the list. The
problem is as follows.

In [2]: np.dtype('i1, i4, i1', align=True)
Out[2]: dtype([('f0', '|i1'), ('', '|V3'), ('f1', 'i4'), ('f2', '|i1')])

In [3]: dtype([('f0', '|i1'), ('', '|V3'), ('f1', 'i4'), ('f2', '|i1')])
---
ValueErrorTraceback (most recent call last)

/home/charris/ipython console in module()

ValueError: two fields with the same name

Note that the second field in the dtype is inserted for alignment purposes
and isn't named. However, the list in the dtype can not be used to define a
dtype because the empty name is replaced by 'f1', which conflicts with the
following field.  The patch attached to the ticket has a rather complicated
work around for this that I would rather avoid. I would prefer some sort of
reserved name for alignment fields, maybe something like '*0', '*1', etc.
Another question I have is if alignment is supposed to be preserved across
architectures, that is, should it be possible to pickle/savez on one
architecture and read things in on another and still have the elements
aligned. I suspect this isn't worth doing, but one way or the other should
be decided.

Thoughts?

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] polynomial: polypow et al not exported

2011-03-02 Thread Ralf Gommers
Hi Charles,

Is it intentional that chebpow/legpow/polypow are not in __all__? That
is breaking crosslinks in the docs and it looks to me like it's just
an oversight.

Cheers,
Ralf
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion