简体   繁体   English

如何将插值项添加到数组?

[英]How to add interpolated item to array?

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?如果我有一个包含 999 个项目(仅限数字)的一维(列),如何在项目 500 和 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=',')

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更多: https://numpy.org/doc/stable/reference/generated/numpy.insert.html

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 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. ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM