[CentralOH] N-dimensional array slicing/crosscutting

Eric Floehr eric at intellovations.com
Thu Dec 8 21:19:23 EST 2016

I was wondering if anyone knows of any way in Python (functional or not),
or a module, that would allow the following:

Let's say I have an n-dimensional array, with keys (numeric or otherwise)
for each dimension. I'd like to be able to set up and grab the elements in
any row in any dimension equally easily.

Here's a simple example, a 2x2 contingency table, with rows labelled
"forecast" and "not forecast" and columns labelled "occurred" and "not
occurred". Within each of the 4 cells, there is some value.

If I set it up traditionally, as a dict within the dict:

table = {}
table['forecast'] = {'occurred': 0, 'not occurred': 0}
table['not forecast'] = {'occurred': 0, 'not occurred': 0}

and access it traditionally:

table['forecast']['occurred'] = 123

The problems are:

1. Set up is hard... I have to duplicate keys, and in an n-dimensional
array, this is a real pain.

2. I always have to access a cell in the right order, and have to remember
that order. It would be great if I could access a cell in the example above
as table['forecast']['occurred'] or table['occurred']['forecast'] (syntax
doesn't matter, table('forecast', 'occurred') is fine too).

3. It's hard to slice... in a 2-dimensional array, it's easy to get the
cells in the outermost dict via table['forecast'].values() but how would I
just as easily (equivalently) get table['not occurred'].values()?

Thoughts? Am I missing something obvious?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20161208/33c0a15f/attachment.html>

More information about the CentralOH mailing list