0

1

currentStep shape is (1, 20, 1)

like in this picture, I want to insert temp value in currentStep last position and remove first position (where 20 corresponding part)

how can I'm to put the value of temp at the end of the currentStep

To express... [:, I want to put temp value in end of here, and remove first position :]

I tried

currentStep = currentStep[:,1:,:]
currentStep[:,-1:,:] = temp

this code is remove last element I want insert temp element

GoBackess
  • 404
  • 3
  • 17

1 Answers1

1

Based on this answer, you could use a combination of np.delete and np.append:

In [20]: inner = [[i] for i in range(20)]

In [21]: arr = np.array([inner])

In [22]: arr.shape
Out[22]: (1, 20, 1)

In [23]: arr = np.delete(arr, 0, 1)

In [24]: arr.shape
Out[24]: (1, 19, 1)

In [61]: np.append(arr[0], [[12]],axis=0)
Out[61]:array([[ 1],[ 2], [ 3], [ 4], [ 5], [ 6], [ 7], [ 8], [ 9],
               [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [12]])

To put it at the beginning use numpy.insert:

np.insert(arr2, 0, 12,1)
rcriii
  • 687
  • 6
  • 9
  • It's what I wanted but, I want 12 to last position `np.insert(currentStep, -1, 12, 1)` doesn't work.... I tried Like this https://imgur.com/6llKlgZ 12 doesn't go last position – GoBackess Aug 09 '19 at 16:41
  • Updated to answer your actual questions. Note that I used axis as a keyword argument in append, I could not get `np.append(arr[0], [[12]], 0)` to work. – rcriii Aug 09 '19 at 18:56