[Numpy-discussion] how to create an array of objects that are sequences?
Sun Jan 6 02:01:27 CST 2008
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
a (i,j) array with each element being a length-k sequence
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.
I guess this really points to the power of n-d arrays!
Here's a simple example:
t = (((1,2),(3,4)),((5,6),(7,8)))
depth 1 -- (4,):
array([(1, 2), (3, 4), (5, 6), (7, 8)], dtype=object)
depth 1 -- (2,)
array([(1, 2, 3, 4), (5, 6, 7, 8)], dtype=object)
(1, 2, 3, 4)
But since there was no object in the original sequence that actually had
a 4-tuple, maybe no one would ever be looking for that.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the Numpy-discussion