python - Select all adjacent elements without copying the numpy array -


i have bunch of points format point = [time, latitude, longitude].

so, have got myself numpy array looks -

points = numpy.array([     [t_0, lat_0, lon_0],     [t_1, lat_1, lon_1],     [t_2, lat_2, lon_2],     ...     [t_n, lat_n, lon_n], ]) 

now, need gives me next , previous points each of these points like:

next_points = numpy.array([     [t_1, lat_1, lon_1],     [t_2, lat_2, lon_2],     ...     [t_n, lat_n, lon_n],     [nan,   nan,   nan],   # note how `nan` put next not exist ])  prev_points = numpy.array([     [nan,   nan,   nan],     [t_0, lat_0, lon_0],     [t_1, lat_1, lon_1],     [t_2, lat_2, lon_2],     ... ]) 

so, can apply distance function -

next_distances = distance_function(points, next_points) prev_distances = distance_function(points, prev_points) 

now, task appears in function gets called in loop around 1000 times,

it nice if next_points , prev_points without creating copy of points.

is there way this?

if understand correctly, shifting array:

if nan-pad points array on both sides, can do

next_points = points[1:] prev_points = points[:-1]  d_next = distance_function(next_points, points[:-1]) d_prev = distance_function(points[1:], prev_points) 

although if true distance function, need either d_next or d_prev , shift again accordingly.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -