Hello, I'm using numarray, I'm wondering about the behaviour of some functions which seem odd to me: 1) When I want to sum all the elements of an array, I can do sum(array) or array.sum() : With the first method
a array([[1, 2], [3, 4]])
numarray.sum(a) array([4, 6])
It seems to be impossible to sum all the elements with sum(array). With the second,
a.sum() 10L
In this case, it's ok but :
b array(1)
b.sum() 0L
I know that it's stupid to sum only one element but it's force me to plan that case in my program (and I don't want to check for each case) if I don't want an error. 2) When I want to replace one element in an array :
a[0,0]=1.1 a array([[1, 2], [3, 4]])
I know that I created the array as an array of integer, but at least I can expect an error message. Anyboby knows if these behaviour are bugs or not ? And if not, I will be glad the have somme explication about the choice of this behaviour. Thanks for your help, Jean-Luc
On Mon, 2005-01-24 at 13:47 +0100, Jean-Luc Menut wrote:
array([[1, 2], [3, 4]])
numarray.sum(a) array([4, 6])
It seems to be impossible to sum all the elements with sum(array).
With the second,
a.sum() 10L
In this case, it's ok but :
b array(1)
b.sum() 0L
This is clearly a bug. In general, rank-0 and zero-length array handling is buggy in numarray because my awareness of these issues came after the fact and these issues were not priorities in Perry's initial design, which was after all to process huge astronomical images memory mapped and across platforms. We've considered ripping out rank-0 altogether several times.
I know that it's stupid to sum only one element but it's force me to plan that case in my program (and I don't want to check for each case) if I don't want an error.
2) When I want to replace one element in an array :
a[0,0]=1.1 a array([[1, 2], [3, 4]])
I know that I created the array as an array of integer, but at least I can expect an error message.
numarray and Numeric, consciously, don't work that way. So, no, you can't expect that.
Anyboby knows if these behaviour are bugs or not ?
rank-0 yes, silent truncation no. Regards, Todd
Am Montag, 24. Januar 2005 14:05 schrieb Todd Miller:
We've considered ripping out rank-0 altogether several times.
Glad you didn't do it! I use them all the time to simplify my code and avoid special case checking. So far, I haven't hit any serious bug, so I assume the code is mostly working for rank-0 arrays by not. Let's hunt down the remaining bugs... :-) -- _________________________________________Norbert Nemec Bernhardstr. 2 ... D-93053 Regensburg Tel: 0941 - 2009638 ... Mobil: 0179 - 7475199 eMail: <Norbert@Nemec-online.de>
A Dilluns 24 Gener 2005 15:50, Norbert Nemec va escriure:
Am Montag, 24. Januar 2005 14:05 schrieb Todd Miller:
We've considered ripping out rank-0 altogether several times.
Glad you didn't do it! I use them all the time to simplify my code and avoid special case checking. So far, I haven't hit any serious bug, so I assume the code is mostly working for rank-0 arrays by not. Let's hunt down the remaining bugs... :-)
This is also my case. rank-0 appears naturally on my code, and, as far as I can tell, they work quite well. --
qo< Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data ""
Hello,
numarray and Numeric, consciously, don't work that way. So, no, you can't expect that.
rank-0 yes, silent truncation no.
I'm sorry, I don't understand very well what is a silent truncation. When I write :
a = array([[1, 2],[3, 4]])
a[0,0]=1.1
I cannot expect to have a = array([[1.1, 2],[3, 4]]) ? How can I solve this problem ? is it possible to force an array to be an array of float ? Thanks, Jean-Luc
On Jan 24, 2005, at 16:19, Jean-Luc Menut wrote:
When I write :
a = array([[1, 2],[3, 4]])
a[0,0]=1.1
I cannot expect to have a = array([[1.1, 2],[3, 4]]) ?
No. All elements in an array are of the same type.
How can I solve this problem ? is it possible to force an array to be an array of float ?
Yes, at creation time: from Numeric import array, Float a = array([[1, 2], [3, 4]], Float) wil create a float array. All the integers are then converted to floats. Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Laboratoire Léon Brillouin, CEA Saclay, 91191 Gif-sur-Yvette Cedex, France Tel.: +33-1 69 08 79 25 Fax: +33-1 69 08 82 61 E-Mail: hinsen@llb.saclay.cea.fr ---------------------------------------------------------------------
participants (5)
-
Francesc Altet -
Jean-Luc Menut -
konrad.hinsen@laposte.net -
Norbert Nemec -
Todd Miller