Hi Francesco,
On Fri, Dec 4, 2015 at 2:32 AM, Francesco Bonazzi
<[email protected]> wrote:
> Hello,
>
> the code I wrote to add N-dim arrays to SymPy is (almost) ready. The only
> point is the order of the constructor arguments.
>
> https://github.com/sympy/sympy/pull/10180
>
> Four classes are provided:
>
> MutableDenseNDimArray
> MutableSparseNDimArray
> ImmutableDenseNDimArray
> ImmutableSparseNDimArray
>
> Immutable ones are SymPy objects (they subclass Expr), mutable ones are not.
> The structure loosely reflects the matrix module.
>
>
> The remaining issue: argument order
>
> Currently the dimensions should preceed the iterable, that is, construction
> would be like:
>
> In [1]: from sympy.tensor.array import *
>
> In [2]: from sympy import *
>
> In [3]: a = ImmutableDenseNDimArray(2, 3, 4, range(2*3*4))
>
> In [4]: a
> Out[4]: [[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]], [[12, 13, 14, 15],
> [16, 17, 18, 19], [20, 21, 22, 23]]]
>
>
>
> SymPy matrices specify dimensions before the iterable:
>
>
> In [5]: Matrix(2, 3, range(6))
> Out[5]:
> Matrix([
> [0, 1, 2],
> [3, 4, 5]])
>
>
> I thought it would be a good idea to preserve that order. Unfortunately,
> being the number of dimensions variable, one cannot (prior to Python 3.5)
> use the shortened form ImmutableDenseNDimArray(*dims, iterable).
>
> Do you think we should postpone the dimensions?
>
> That is:
>
> ImmutableDenseNDimArray(iterable, *dims)
>
> instead of
>
> ImmutableDenseNDimArray(dim1, dim2, ... , iterable)
>
> Consider that the different standard used in matrices could be resolved by
> adding a new argument order in the matrix construction, e.g. by allowing an
> expression like Matrix(range(6), 2, 3) to mean Matrix(2, 3, range(6)).
I would try to stay close to NumPy. I am actually not sure how to
properly construct 3D arrays. One way is this:
In [12]: reshape(array(range(2*3*4)), (2, 3, 4))
Out[12]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
So for this reason, it looks like your proposal
ImmutableDenseNDimArray(iterable, *dims)
is better. We can provide perhaps a shape argument, to be used as follows:
ImmutableDenseNDimArray(range(2*3*4), shape=[2, 3, 4])
Ondrej
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CADDwiVANyerbj%3D5jckf5iDo-jWuxiDd55XJO%2BPxWB7g8Xq%2BxpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.