How to insert NaN array into a numpy 2D array
Question: I'm trying to insert an arbitrary number of rows of NaN values within a 2D
array at specific places. I'm logging some data from a microcontroller in a
.csv file and parsing with python.

The data is stored in a 3 column 2D array like this

    
    
    [(122.0, 1.0, -47.0) (123.0, 1.0, -47.0) (125.0, 1.0, -44.0) ..., 
    (39.0, 1.0, -47.0) (40.0, 1.0, -45.0) (41.0, 1.0, -47.0)]
    

The first column is an sequence counter. What I'm trying to do is iterate
through the sequence values, diff current and previous sequence number and
insert as many rows with nan as there are missing sequences.

Basically,

    
    
    [(122.0, 1.0, -47.0) (123.0, 1.0, -47.0) (125.0, 1.0, -44.0)]
    

would become

    
    
    [(122.0, 1.0, -47.0) (123.0, 1.0, -47.0) (nan, nan, nan) (125.0, 1.0, -44.0)]
    

However the following implementation of `np.insert` produces an error

    
    
    while (i < len(list[1])):
         pid = list[i][0]
         newMissing = (pid - LastGoodId + 255) % 256
         TotalMissing = TotalMissing + newMissing
         np.insert(list,i,np.zeros(newMissing,1) + np.nan)   
         i = i + newMissing
         list[i][0] = TotalMissing
         LastGoodId = pid 
    

> \---> 28 np.insert(list,i,np.zeros(newMissing,1) + np.nan) 29 i = i +
> newMissing 30 list[i][0] = TotalMissing
>
> TypeError: data type not understood

Any ideas on how I can accomplish this?


Answer: From the [doc of
`np.insert()`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.insert.html):

    
    
    import numpy as np
    a = np.arrray([(122.0, 1.0, -47.0), (123.0, 1.0, -47.0), (125.0, 1.0, -44.0)]))
    np.insert(a, 2, np.nan, axis=0)
    array([[ 122.,    1.,  -47.],
           [ 123.,    1.,  -47.],
           [  nan,   nan,   nan],
           [ 125.,    1.,  -44.]])
    

