"Alexander Michael" <[EMAIL PROTECTED]> writes: > How can I do something like the following? > > a = empty((5,7), dtype=<4 element array of floats>) > > c = a[:,-1] # last column of 4 element arrays > > a[0,0] = 2.0 > print a[0,0] > [2. 2. 2. 2.] > > a[1,0] = 3.0 > a[0,1] = a[0,0] * a[1,0] > > print a[0,1] > [6. 6. 6. 6.]
The nearest I could come with is:: .>>> import numpy .>>> a = numpy.zeros((5,7), numpy.dtype('object')) .>>> a[:,:]=None .>>> class O: .... def __init__(self, val): .... self.val = val .... def __mul__(self, other): .... return self.__class__(self.val*other.val) .... def __str__(self): .... return "%s" % (numpy.ones(4, numpy.dtype('float')) * self.val) .... .>>> a[0,0] = O(2.0) .>>> print a[0,0] [ 2. 2. 2. 2.] .>>> a[1,0] = O(3.0) .>>> a[0,1] = a[0,0] * a[1,0] .>>> print a[0,1] [ 6. 6. 6. 6.] Regards -- _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion