symbolic icon indicating copy to clipboard operation
symbolic copied to clipboard

Support Multidimentional

Open latot opened this issue 9 years ago • 6 comments

Well, this part is pending, support multidimensional matrix, sadly i'm lack of knowlodge of python to work here, i try search but no lucky.

ex:

a(1,1,1)=1
a(1,2,1)=2
a(3,1,1)=3

a of 3 dims.

well my problem in python is how acces to other dimentions without use this Array[a][b][c], to automated this i think we need some mere flexible access.

latot avatar Jan 11 '16 03:01 latot

SymPy tensors is probably the way to go, but I haven't looked at it yet.

cbm755 avatar Jan 11 '16 06:01 cbm755

I saw this upstream: https://github.com/sympy/sympy/pull/11800, so looks like its do-able now/soonish.

cbm755 avatar Nov 04 '16 07:11 cbm755

http://docs.sympy.org/latest/modules/tensor/array.html

Upabjojr avatar Nov 04 '16 07:11 Upabjojr

well my problem in python is how acces to other dimentions without use this Array[a][b][c], to automated this i think we need some mere flexible access.

It's advisable to use 1-dim arrays as internal data structure, and then establish a conversion criterion from the multidimensional index to the 1-dim indexing. It's more efficient and easier to handle than nested lists.

Another alternative: a dictionary of indices mapping to the values.

Upabjojr avatar Nov 04 '16 14:11 Upabjojr

Thanks @Upabjojr you're very welcome to help us here if you'd like!

My feeling is this task might be easier after we have a better communication mechanism between Octave and Python ("Pytave project").

But some things work already:

>> syms x
>> Q = sym('Array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])')
Q = (sym) [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
>> A = x*Q
A = (sym) [[[x, 2*x], [3*x, 4*x]], [[5*x, 6*x], [7*x, 8*x]]]
char(A)
ans = ImmutableDenseNDimArray(Tuple(Symbol('x'), Mul(Integer(2), Symbol('x')), Mul(Integer(3), Symbol('x')), Mul(Integer(4), Symbol('x')), Mul(Integer(5), Symbol('x')), Mul(Integer(6), Symbol('x')), Mul(Integer(7), Symbol('x')), Mul(Integer(8), Symbol('x'))), Tuple(Integer(2), Integer(2), Integer(2)))

cbm755 avatar Nov 05 '16 00:11 cbm755

Note, actually is possible in Sympy access to elements in this way:

a = Array(............)
a[(1, 2, 3, 4)] = val
a[(4, 2, 3, 1)]

there you can set and get data with tuples.

latot avatar Nov 05 '16 04:11 latot