[Tutor] Question concerning splitting of arrays

Weber, Derek Derek.Weber at dsto.defence.gov.au
Wed Sep 29 09:48:24 CEST 2004


Hi all,

I'm actually doing something like translating some matlab code to Python and am wondering whether it's possible to split multi-dimensional arrays as such:

>>> array = [[11, 12, 13], [21, 22, 23], [31, 32, 33]]
>>> firstColumn = array[:][0]
>>> lowerRightCorner = array[1:][1:]
>>> print firstColumn
[[11], [21], [31]]
>>> print lowerRightCorner
[[22, 23], [32, 33]]

I seem to get errors when I do this, so I thought I'd ask people who knew a great deal more about the language than I did to see if there's an easy way to do this, or do I have to write some functions to do it for me?

I think the issue is making the first array reference a range.

Any suggestions would be gratefully accepted. Also, if there's a way to search the archive of the list, I'd do that, but I haven't had any luck with the one referred to by python.org.

Thanks very much.

D. 

============================================================
Derek Weber                  derek.weber at dsto.defence.gov.au
Information Exploitation Group            Rm: 2.H.06 205Labs
Defence Science & Technology Organisation Ph: 61 8 8259 7699
PO Box 1500, Edinburgh SA 5111            Fx: 61 8 8259 5619
============================================================



More information about the Tutor mailing list