[Numpy-discussion] Scalar array - a trap for the unwary

Colin J. Williams cjw at sympatico.ca
Mon Jan 23 14:32:29 CST 2006

Travis Oliphant wrote:

> Colin J. Williams wrote:
>> In exploring these matters, it seems that numpy does not broadcast 
>> scalar operations on arrays, as numarray does.  Is this intended?  
>> Please see the script below and the result under that.
> I don't know what is going on with your installation, because I don't 
> get that error.  Your script works fine for me.

I've just tried this with version 0.9.4 and all works well.
 >>> a= _mu.array([1, 2], dtype= _nt.uint8)
 >>> a+254
array([255, 256], dtype=int16)

This does bring out a possible problem with the new type.  str of the 
old type returned the input name int8, float64 etc.  Is there some 
method of the new type which returns the name input, 'int8' in the above 
example?  In most cases, the mnemonic is more helpful than the letter 

> I wouldn't advise extracting array directly from multiarray as you are 
> doing, because exactly where array lives is an implementation detail 
> that could change in the future.

I accept this risk for now.  Partly, this was done to simplify the 
namespace and partly to locate a bug concerning the interaction of a 
Windows debugger and the umath module.

> -Travis
Colin W.

More information about the Numpy-discussion mailing list