George Sakkis wrote: > Can anyone explain this ? > > >>>> import numpy as N >>>> x = N.arange(1,6,dtype='B') >>>> x >>>> > array([1, 2, 3, 4, 5], dtype=uint8) > >>>> N.repeat(x, N.ones(5,'H')) >>>> > array([1, 2, 3, 4, 5], dtype=uint8) > >>>> N.repeat(x, N.ones(5,'l')) >>>> > array([1, 2, 3, 4, 5], dtype=uint8) > >>>> N.repeat(x, N.ones(5,'L')) >>>> > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File > "/usr/local/lib/python2.4/site-packages/numpy/core/fromnumeric.py", > line 83, in repeat > return repeat(repeats, axis) > TypeError: array cannot be safely cast to required type > It means you can't safely a value of type uint32 ('L') to a value of type int32 ('i'). The second argument of repeat needs to be castable to type int32.
A style note: please use the named dtypes (int32, uint32, etc) rather than the old-style letter codes; the former is much clearer. The answer to your question might have been immediately apparent had you been using named dtypes. Personally, I'd also prefer people use the "ones([n])" syntax instead of the I-wish-it-were-deprecated-but-it's-too-much-to-hope-for "ones(n)" syntax. T -tim ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion