[Matrix-SIG] Casts and slices
Sat, 13 Mar 1999 20:16:25 -0500 (EST)
Greetings, fellow NumPyers
First off, thanks to all the noble souls who created NumPy and
then shared it with the rest of us :) Having just changed from
an environment where unlimited IDL (in fact, PV WAVE) licenses
were available to a place where no IDL is available, I did
appreciate NumPy's availability :)
I have a question about what might be a possible inconsistency:
>>> b = reshape(ones(20, 'f'), (10,2))
>>> b[:,0] = b[:,1] # This works fine: both sides are of the same type.
>>> b[:,0] = sqrt(b[:,1]) # This also works fine.
>>> b[:,0] = b[:,1]**3 # Should this not also work if sqrt works?
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: Array can not be safely cast to required type
If the previous does not work because it attempts to cast a
double (right hand side) into a float, then should the following
not also produce an error, since each element of the list is
a Python double:
>>> b[:,0] = (b[:,1]**3).tolist() # It works.
>>> b[:,0] = map(float, b[:,1]**3) # It also works.
Since many operations have right hand sides which are doubles,
I was wondering if there is an easier way to assign results to
float array elements than using the tolist() method or map().
A second question: using take() one can access noncontiguous
elements of an array. Is there a way to also assign values to
noncontiguous elements? I mean something like:
b[(0,1,4)] = [1.2, 3.4, 5.3]
One last question is also coming under a different subject.