From: Paul F. D. <pa...@pf...> - 2001-07-10 20:09:54
Attachments:
changes.txt
|
Release 20.1 is available for your dining pleasure. |
From: Chris B. <chr...@ho...> - 2001-07-20 00:10:47
|
Hi all, I am using a 2-d array to store values that will be an index into a list. It is huge, sot to samve space I have used a type Int16. Now when I pull a value outl it is of type array, so it can not be used to index a sequence. The strange thing is that it works if the array is of rank 1. Some tests: >>> from Numeric import * >>> >>> l = range(10) # a test list >>> a = arange(10) # an array if Ints >>> print type(a[3]) <type 'int'> #So this is an Int >>> print l[a[3]] 3 # and it can be used as an index. >>> a.shape = (2,5) #reshape it to be rank-2 >>> print type(a[1,3]) <type 'int'> # still and Int >>> print l[a[1,3]] 8 # and still usable as an index. # now change the type >>> a = a.astype(Int16) >>> a.shape = (10,) >>> print type(a[3]) <type 'int'> #it's an Int >>> a.shape = (2,5) # now change the shape to rank-2 >>> print type(a[1,3]) <type 'array'> #!!!!!!!#### # Now a single item is of type 'array' >>> print l[a[1,3]] Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: sequence index must be integer # and it can not be used as an index! I can work around this with an explicite type cast with int(), but it seems like wierd behaviour to me. I am accesing a single item, it is typcaste as an Int when the item is pulled out of a rank-1 array, but it is a rank-0 array when pulled from a rank > 1 array. Any ideas what causes this? Is there a good reson for htis, or is it a bug? -Chris -- Christopher Barker, Ph.D. Chr...@ho... --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ |
From: Emmanuel V. <vi...@li...> - 2001-07-20 07:18:42
|
Feature, I think. a[1,3] is a rank-0 array, with typecode Int16. There is no other way to handle a Int16 scalar in Python (Int16 is not a python type). This solution allows to correctly propagate the types in array arithmetic, without unwanted upcasts. Emmanuel Chris Barker wrote: > # now change the type > >>> a = a.astype(Int16) > >>> a.shape = (10,) > >>> print type(a[3]) > <type 'int'> > #it's an Int > > >>> a.shape = (2,5) > # now change the shape to rank-2 > > >>> print type(a[1,3]) > <type 'array'> > >>> print a[0,0].typecode() 's' # == Int16 >>> a[0,0].shape () # rank-0 array |
From: Konrad H. <hi...@cn...> - 2001-07-20 12:31:00
|
> Feature, I think. Right, but a relatively recent one. In the first NumPy releases, the result was a scalar Integer object. There are good arguments for both variants. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hi...@cn... Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- |
From: Chris B. <chr...@ho...> - 2001-07-20 18:30:54
|
Konrad Hinsen wrote: > > > Feature, I think. > > Right, but a relatively recent one. In the first NumPy releases, the > result was a scalar Integer object. There are good arguments for both > variants. OK. I see that there are trade-offs either way, and I certainly see the benefit of keeping the precision consistent(even though it would be easier in this case to have th upcast). I do think it's a bug, however, to have the upcast when pulling a single value out of a 1-d array, but not when pulling it out of a higher rank array: >>> a = array(((1,2,3),(4,5,6)),Int16) >>> type(a[1,1]) <type 'array'> >>> a.shape = (6,) >>> type(a[2]) <type 'int'> >>> This seems totally inconsistant. Note that this same effect occurs for arrays of type Float16 (and probably others) By the way, would it be at all possible for Python to accept an array of rank 0 as an index? How big a change would that be? -Chris -- Christopher Barker, Ph.D. Chr...@ho... --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ |