[Numpy-discussion] how to create an array of objects that are sequences?

Robert Kern robert.kern@gmail....
Sun Jan 6 02:22:02 CST 2008


Christopher Barker wrote:
> Robert Kern wrote:
>> Chris Barker wrote:
>>> What if your "objects" were nested sequences, and you wanted to partly 
>>> flatten them -- which would you flatten?
>> I'm pretty sure that that is exactly the ambiguity that the depth option
>> resolves. Can you give me an example where it's still ambiguous with the depth
>> information provided?
> 
> I was imagining:
> 
> Say you have a bunch of nested sequences that, fully expanded, would 
> yield a (i,j,k) rank-3 array. If you wanted a rank-2 array, you could 
> have either:
> a (i,j) array with each element being a length-k sequence
> or:
> a (i,k) array, with each element being a length-j sequence.
> 
> This is quite trivial with numpy n-d arrays.
> 
> However, while you could build either of those from nested sequences, 
> there isn't, in fact, and object in there that is that length-j sequence.

And I think that's the key difference. I don't think array() should be 
responsible for *arbitrarily* flattening nested sequences in order to 
reinterpret structure. Instead, I think we really only need array() to be able 
to answer the question, "is this object an atom or a sequence I need to descend 
into?" Essentially, for all valid index-tuples (say, [i,j,k]) in the array:

   arr[i,j,k] == original[i,j,k]

> I guess this really points to the power of n-d arrays!

Yes. Since one can get the (i,k) array after getting the (i,j,k) array and 
reshaping, I don't think we need to support it in array().

-- 
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


More information about the Numpy-discussion mailing list