If I have a one dimensional (column) that has 999 item (numbers only), how can I put an interpolated number between the item 500 and 501?
a=np.array(h5py.File('/Users/Ad/Desktop//H5 Files/3D.h5', 'r')['Zone']['TOp']['data'])
output = np.column_stack((a.flatten(order="C"))
np.savetxt('merged.csv',output,delimiter=',')
CodePudding user response:
What you want to achieve is not clear, but try
numpy.insert(array, 501, value)
Note that the second argument is the index before which the new element will be inserted.
More: https://numpy.org/doc/stable/reference/generated/numpy.insert.html
CodePudding user response:
With such a short array, you could just add the value to the end and sort!
Still, you can find the index and insert it!
https://numpy.org/doc/stable/reference/generated/numpy.insert.html
Beware, you may need to change the type of your array to insert a non-integer value
>>> arr = np.arange(10)
>>> np.insert(arr, 5, 4.4)
array([0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9])
>>> np.insert(arr.astype("float64"), 5, 4.4)
array([0. , 1. , 2. , 3. , 4. , 4.4, 5. , 6. , 7. , 8. , 9. ])