【问题标题】:Changing size/length of ndarray?改变ndarray的大小/长度?
【发布时间】:2020-06-02 13:18:14
【问题描述】:

我有一个抛射运动

y0 = [0., 0., 15 * np.cos(alpha), 15 * np.sin(alpha)]
time = np.linspace(0, 5, num=10000)
res = ode.odeint(func, y0, time)

要删除 y-axis 的负值,我使用

yy = np.delete(res[:, 1], np.where(res[:, 1] < 0)[0], axis=0)

但是如何改变

res[:, 0] =     # xaxes
res[:, 2] =     # velocity x-direction
res[:, 3] =     # velocity y direction

更改后与y-axis 相同的长度/大小数组?

【问题讨论】:

  • 没有办法直接做到这一点。应该保存已删除的索引,然后使用该索引列表将其删除到 x 数组中。

标签: python physics numpy-ndarray


【解决方案1】:

正如@AerysS 在 cmets 中提到的,您需要保存要删除的索引:

indices = np.where(res[:, 1] < 0)[0]
x_ = np.delete(res[:, 1], indices, axis=0)
y_ = np.delete(res[:, 2], indices, axis=0)
...

【讨论】:

    猜你喜欢
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多