[Numpy-discussion] Data types in Numerical Python
Lane Brooks
lbrooks@MIT....
Sun Oct 12 10:23:34 CDT 2008
Linda Seltzer wrote:
>> Here is an example that works for any working numpy installation:
>>
>> import numpy as npy
>> npy.zeros((256, 256))
>>
> This suggestion from David did work so far, and removing the other import
> line enabled the program to run.
> However, the data types the program used as defaults for variables has
> changed, and now I am getting error messages about data types. It seems
> that some variables are getting a default designation as floats. Before I
> installed numpy and needed 2-D arrays, the program was working with the
> default types, and I did not have to specify types.
> Is there a clear tutorial that describes a means to assign data types for
> each variable as in C, so that I don't obtain error messages about data
> types?
> Because I am simulating code for a DSP processor, the data types I need
> are unsigned bytes, unsigned 32-bit ints, and signed 32-bit ints. In some
> cases I can use unsigned and signed 16-bit ints.
> Also, what data types are valid for use with local operations such as
> exclusive or?
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
You can specify the type in the zeros command
import numpy as npy
npy.zeros((256, 256), npy.uint32)
or you can convert an array between types at any point using the
.astype(npy.uint16) notation like this
npy.zeros((256,256)).astype(npy.uint16)
I am not sure if there are any tutorials on this, but here are the types
you are interested in:
npy.uint32
npy.uint16
npy.int32
npy.int16
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081012/9916a541/attachment.html
More information about the Numpy-discussion
mailing list