Hi, On 29 September 2011 04:52, Torquil <[email protected]> wrote:
> Hi everybody! > > What is the simplest way of constructing e.g. a (2,3,4)-shaped numpy > array containing sympy zeros? > The simplest, but maybe not the most efficient is: In [1]: import numpy as np In [2]: a = S.Zero*np.zeros((2, 3, 4)) In [3]: all([ type(x) == C.Zero for x in flatten(a.tolist()) ]) Out[3]: True You can also use: In [18]: b = np.zeros((2, 3, 4), dtype=object) In [19]: b.fill(S.Zero) In [20]: all([ type(x) == C.Zero for x in flatten(b.tolist()) ]) Out[20]: True > At the moment, I'm doing > > a = numpy.array(sympy.zeros((1,2*3*4))).reshape((2,3,4)) > > but I think that having to reshape is a bit ugly. > > I am also considering: > > a = numpy.zeros((2,3,4),dtype='object') > I hoped that something like np.zeros((2, 3, 4), dtype=Integer) would work, but apparently the resulting dtype is object and elements are instances of int type. > > which makes it possible to later do e.g. > > from sympy.abc import x > a[0,0,0] = x > > but I'm not sure if there are some unfortunate side-effects if I don't > make sure to set all components explicitely to be sympy quantities? > > On a related note, it is possible to just tell numpy that the default > value of each component in an array should be: > > <class 'sympy.core.numbers.Zero'> ? > > I'm using sympy 0.6.7 and numpy 1.6.1 > btw. 0.6.7 is a very old version of SymPy. The newest is 0.7.1. > > Thanks! > Torquil Sørensen > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > Mateusz -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
