<jupyter_start><jupyter_text>03 ``numpy.array`` 基础<jupyter_code>import numpy
numpy.__version__
import numpy as np
np.__version__<jupyter_output><empty_output><jupyter_text>Python List的特点<jupyter_code>L = [i for i in range(10)]
L
L[5]
L[5] = 100
L
L[5] = "Machine Learning"
L<jupyter_output><empty_output><jupyter_text>Python的List不要求存储同样的类型，带来效率问题。<jupyter_code>import array
arr = array.array('i', [i for i in range(10)])
arr
arr[5]
arr[5] = 100
arr
arr[5] = "Machine Learning"
arr[5] = 5.0<jupyter_output><empty_output><jupyter_text>``array``的缺点是没有将数据当做向量或者矩阵，不支持基本运算。  ``numpy.array``<jupyter_code>nparr = np.array([i for i in range(10)])
nparr
nparr[5] = 100
nparr
nparr[5] = "Machine Learning"
nparr.dtype
nparr[5] = 5.0
nparr
nparr.dtype
nparr[5] = 3.14
nparr<jupyter_output><empty_output><jupyter_text>这里注意nparr 中3.14被截断成了3<jupyter_code>nparr2 = np.array([1, 2, 3.0])
nparr2.dtype<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15191256830601094, 'fraction_numerical': 0.04918032786885246, 'mean_word_length': 8.346938775510203, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '93700', 'license': 'Apache-2.0', 'n_tokens_mistral': 480, 'n_tokens_neox': 473, 'n_words': 69, 'path': '03-Jupyter-Notebook-Numpy-and-Matplotlib/03-Numpy-Array-Basics/03-Numpy-Array-Basics.ipynb', 'repo_name': 'mtianyan/Mtianyan-Play-with-Machine-Learning-Algorithms', 'size': '915'}