[Numpy-discussion] scalar recordarrays

Matthew Koichi Grimes mkg@cs.nyu....
Mon Mar 19 14:59:12 CDT 2007

Francesc Altet wrote:
> with a
> rank-0 'recarr', 'recarr.x' should return a rank-0 array (for
> consistency), but it doesn't:
> In [74]:recarr=numpy.rec.array((1.0, 0, 3), dtype)
> In [75]:recarr.x
> Out[75]:1.0
> In [76]:type(recarr.x)
> Out[76]:<type 'numpy.float64'>
> While I find this inconsistent, I'm not sure whether it should be be
> fixed or not because the boundaries between rank-0 and scalar objects
> are always a bit fuzzy. Travis can probably bring more light here.
Here's my case for "yes, it's a problem that should be fixed (please?)": 
In my particular project, this inconsistency becomes a pervasive problem 
when writing vectorized functions that are supposed to accept and return 
tensors of various ranks. To accomodate the inconsistency, one has to 
take what would have been a simple statement of the form:

output.x[...] = blah

and replace it with a bunch of boolean switches:

if output.ndim == 0:
    output = output.reshape([1])
    outputWas0dim = True
    outputWas0dim = False

output.x[...] = blah

if outputWas0dim:
    output =  output.reshape([])

return output

-- Matt

More information about the Numpy-discussion mailing list