我想使用 numpy 从 python 中的数组中排除起点。我该如何执行?例如,我想排除 0,但想从下一个实数继续(即想从大于 0 开始运行)以下代码x=np.linspace(0,2,10)
问问题
2813 次
2 回答
2
有点老问题,但我想我会分享我对这个问题的解决方案。
假设你想得到一个数组
[0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.]
您可以使用 np.linspace() 中的端点选项并反转方向:
x = np.linspace(2, 0, 10, endpoint=False)[::-1]
[::-1]
反转数组,使其最终处于所需的序列中。
于 2021-07-08T13:40:25.050 回答
2
x=np.linspace(0,2,10)[1:] #remove the first element by indexing
print(x)
[0.22222222 0.44444444 0.66666667 0.88888889 1.11111111 1.33333333
1.55555556 1.77777778 2. ]
于 2020-06-26T12:29:26.730 回答