1. 使用`list()`函数和`input()`函数:
my_array = list(map(int, input("Enter the elements of the array, separated by spaces: ").split()))
2. 使用`numpy.array()`函数:
import numpy as np
my_array = np.array(list(map(int, input("Enter the elements of the array, separated by spaces: ").split())))
3. 使用`input()`函数和`for`循环来构建一维数组:
arr = input("Enter the elements of the array, separated by spaces: ")
num = [int(n) for n in arr.split()]
print(num)
4. 对于二维数组,你可以先输入行数和列数,然后逐行输入:
n = int(input("Enter the number of rows and columns for the 2D array: "))
line = []
for i in range(n):
line.append(list(map(int, input("Enter row {} elements separated by spaces: ".format(i+1)).split())))
print(line)
请根据你的需求选择合适的方法。