1. 使用`print`函数:
a = [1, 2, 3]print(a)
2. 使用`numpy`库的`print`函数:
import numpy as npa = np.array([1, 2, 3])print(a)
3. 使用`numpy`库的`set_printoptions`函数来设置输出精度:
import numpy as npa = np.array([1, 2, 3])np.set_printoptions(precision=3)print(a)

4. 使用`for`循环逆序输出数组:
a = [1, 2, 3, 4, 5, 6, 7]for i in range(len(a)-1, -1, -1):print(a[i])
5. 使用`numpy`库的`set_printoptions`函数来设置输出格式,例如设置每列的宽度:
import numpy as npa = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])np.set_printoptions(linewidth=10)print(a)
6. 使用`numpy`库的`set_printoptions`函数来设置输出格式,例如设置每行的最大元素数:
import numpy as npa = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])np.set_printoptions(threshold=5)print(a)
以上方法可以帮助你在Python中输出数组。
