如何在给定范围内创建 numpy 数组?
pythonnumpyserver side programmingprogramming更新于 2024/9/21 18:20:17
我们必须在用户提供的范围内创建一个 numpy 数组。我们将使用 numpy 库中的 arange() 函数来获取输出。
算法
步骤 1:导入 numpy。 步骤 2:从用户那里获取 start_value、end_value 和 Step。 步骤 3:使用 numpy 中的 arange() 函数打印数组。
示例代码
import numpy as np
start_val = int(input("Enter starting value: "))
end_val = int(input("Enter ending value: "))
Step_val = int(input("Enter Step value: "))
print(np.arange(start_val, end_val, Step_val))
输出
Enter starting value: 5 Enter ending value: 50 Enter Step value: 5 [ 5 10 15 20 25 30 35 40 45]
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

