如何在給定的範圍內建立一個 numpy 陣列?
我們必須在使用者提供的範圍內建立一個 numpy 陣列。我們將使用 numpy 庫中的 arange() 函式來獲得我們的輸出。
演算法
Step1: Import numpy. Step 2: Take start_value, end_value and Step from the user. Step 3: Print the array using arange() function in numpy.
示例程式碼
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]
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP