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.
After messing around with it, I think manually assigning dtype does a reinterpret cast rather than what you want. Meaning I think it interprets the data directly as a float rather than converting it to one. Maybe you could try `aa = numpy.array(aa.map(float, aa))`.

Further Explanation: dtype is the type of the data. To quote verbatim from the [documentation](http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html)

> 
> A data type object (an instance of numpy.dtype class) describes how
>  the bytes in the fixed-size block of memory corresponding to an array
>  item should be interpreted.
> 
> 
> 

ints and floats don't have the same bit patterns, meaning you can't just look at the memory for an int and it would be the same number when you look at it as a float. By setting dtype to float64 you are just telling the computer to read that memory as float64 instead of actually converting the integer numbers to floating point numbers.