Question: I am new to Python, and don't understand what `.dtype` does.   
For example:

```
>>> aa
array([1, 2, 3, 4, 5, 6, 7, 8])
>>> aa.dtype = "float64"
>>> aa
array([  4.24399158e-314,   8.48798317e-314,   1.27319747e-313,
     1.69759663e-313])

```

I thought dtype is a property of aa, which should be int, and if I assign `aa.dtype = "float64"`   
 then`aa` should become `array([1.0 ,2.0 ,3.0, 4.0, 5.0, 6.0, 7.0, 8.0])`.

Why does it changes its value and size?   
What does it mean?

I was actually learning from a piece of code, and shall I paste it here:

```
def to_1d(array):
 """prepares an array into a 1d real vector"""
    a = array.copy() # copy the array, to avoid changing global
    orig_dtype = a.dtype
    a.dtype = "float64" # this doubles the size of array
    orig_shape = a.shape
    return a.ravel(), (orig_dtype, orig_shape) #flatten and return

```

I think it shouldn't change the value of the input array but only change its size. Confused of how the function works

Answer: 
By changing the dtype in this way, you are changing the way a fixed block of memory is being interpreted. 

Example:

```
>>> import numpy as np
>>> a=np.array([1,0,0,0,0,0,0,0],dtype='int8')
>>> a
array([1, 0, 0, 0, 0, 0, 0, 0], dtype=int8)
>>> a.dtype='int64'
>>> a
array([1])

```

Note how the change from `int8` to `int64` changed an 8 element, 8 bit integer array, into a 1 element, 64 bit array. It is the same 8 byte block however. On my i7 machine with native endianess, the byte pattern is the same as `1` in an int64 format. 

Change the position of the 1:

```
>>> a=np.array([0,0,0,1,0,0,0,0],dtype='int8')
>>> a.dtype='int64'
>>> a
array([16777216])

```

Another example:

```
>>> a=np.array([0,0,0,0,0,0,1,0],dtype='int32')
>>> a.dtype='int64'
>>> a
array([0, 0, 0, 1])

```

Change the position of the `1` in the 32 byte, 32 bit array:

```
>>> a=np.array([0,0,0,1,0,0,0,0],dtype='int32')
>>> a.dtype='int64'
>>> a
array([         0, 4294967296,          0,          0]) 

```

It is the same block of bits reinterpreted.
The [documentation](http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.dtype.html#numpy.ndarray.dtype) for the `dtype` attribute of `ndarray` is not very useful at all. Looking at your output it would seem that the buffer of eight 4 byte integers is being reinterpreted as four 8 byte floats.

But what you want is to specify the `dtype` in the array creation:

```
array([1, 2, 3, 4, 5, 6, 7, 8], dtype="float64")

```