python中numpy.ndarray与list的区别?以及用matplotlab.pyplot绘图时的注意事项。
生活随笔
收集整理的這篇文章主要介紹了
python中numpy.ndarray与list的区别?以及用matplotlab.pyplot绘图时的注意事项。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import matplotlib.pyplot as plt
import numpy as np# 創建numpy.ndarray
L=np.array([1,2,3,4,5])print('#'*50)print(L)print('L類型:\n{}'.format(type(L)))print('#'*50)L2=L.tolist()print(L2)print('L2類型:\n{}'.format(type(L2)))print('#'*50)plt.plot(L,'s',label='Ridge alpha=1')plt.show()
##################################################
[1 2 3 4 5]
L類型:
<class 'numpy.ndarray'>
##################################################
[1, 2, 3, 4, 5]
L2類型:
<class 'list'>
##################################################
L3=np.array([[1,2,3,4,5],[2,3,4,5,6]])print('#'*50)print(L3)print('L3類型:\n{}'.format(type(L3)))print('#'*50)plt.plot(L3,'s',label='Ridge alpha=1')plt.show()
##################################################
[[1 2 3 4 5][2 3 4 5 6]]
L3類型:
<class 'numpy.ndarray'>
##################################################
總結
以上是生活随笔為你收集整理的python中numpy.ndarray与list的区别?以及用matplotlab.pyplot绘图时的注意事项。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python_numpy笔记:
- 下一篇: 深入浅出python机器学习_4.3.1