<jupyter_start><jupyter_text>___ ___  NumPy - https://mp.weixin.qq.com/s/lFCojLwoMmDqSnzJSBpJQg 【Numpy上】- https://mp.weixin.qq.com/s/YzhjLGXJNaqrAfP-6QwXRw 【Numpy下】Numpy （Numerical Python）是 Python 专门处理高维数组 (high dimensional array) 的计算的包。 Numpy 运行速度快，主要用于数组计算，包含：- N维数组 ndarray- 广播功能 Broadcast- 代数、变化、随机数等官网：www.numpy.org  引入 NumPy<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Numpy 数组NumPy 数组是我们在整个课程中使用 Numpy 的主要方式。 Numpy 数组本质上有两种形式：向量和矩阵。- 向量是严格的一维数组- 矩阵是二维的（但注意，矩阵仍然只能有一行或一列）。现在介绍如何创建 NumPy 数组。 创建 Arrays From a Python List<jupyter_code>my_list = [1,2,3]
my_list
np.array(my_list)
my_matrix = [[1,2,3],[4,5,6],[7,8,9]]
my_matrix
np.array(my_matrix)
np.array(my_matrix)[:,1]
list(zip(*my_matrix))[0]<jupyter_output><empty_output><jupyter_text>Built-in 方法  arange在给定的间隔内返回均匀间隔的值。<jupyter_code>np.arange(0,10)
np.arange(0,11,2)<jupyter_output><empty_output><jupyter_text>zeros & ones生成零或一的数组。<jupyter_code>np.zeros(3)
np.zeros((5,5))
np.ones(3)
np.ones((3,3))<jupyter_output><empty_output><jupyter_text>linspaceReturn evenly spaced numbers over a specified interval.<jupyter_code>np.linspace(0,10,3)
np.linspace(0,10,50)<jupyter_output><empty_output><jupyter_text>eyeCreates an identity matrix<jupyter_code>np.eye(4)<jupyter_output><empty_output><jupyter_text>Random 产生随机数组 rand创建给定形状的数组并填充它来自均匀分布的随机样本。<jupyter_code>np.random.seed(2)
np.random.rand(2)
np.random.rand(5,5)<jupyter_output><empty_output><jupyter_text>randn从“标准正态”分布中返回一个（或多个）样本。与均匀分布的`rand`不同<jupyter_code>np.random.randn(2)
np.random.randn(5,5)<jupyter_output><empty_output><jupyter_text>randint返回从“低”（包括）到“高”（不包括）的随机整数。<jupyter_code>np.random.randint(1,100)
np.random.randint(1,100,10)<jupyter_output><empty_output><jupyter_text>数组性质（attribute）和方法（method）<jupyter_code>arr = np.arange(25)
ranarr = np.random.randint(0,50,10)
arr
ranarr<jupyter_output><empty_output><jupyter_text>重塑（reshape）返回包含具有新形状的相同数据的数组。<jupyter_code>arr.reshape(5,5)<jupyter_output><empty_output><jupyter_text>max / min / argmax / argmin这些是查找最大值或最小值的方法。或者使用 `argmin` 或 `argmax` 找到它们的索引位置。<jupyter_code>ranarr
ranarr.max()
ranarr.argmax()
ranarr.min()
ranarr.argmin()<jupyter_output><empty_output><jupyter_text>形状（shape）形状是数组具有的属性（不是方法）<jupyter_code># Vector
arr.shape
# Notice the two sets of brackets
arr.reshape(1,25)
arr.reshape(1,25).shape
arr.reshape(25,1)
arr.reshape(25,1).shape<jupyter_output><empty_output><jupyter_text>数据类型（dtype）还可以获取数组中对象的数据类型<jupyter_code>arr.dtype<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14977795720629794, 'fraction_numerical': 0.03068227694792087, 'mean_word_length': 12.180851063829786, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '515719', 'license': 'MIT', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1404, 'n_words': 103, 'path': 'porto-seguro-safe-driver-prediction/Phase1/Numpy&Pandas/Numpy/01-NumPy Arrays.ipynb', 'repo_name': 'datoujinggzj/WhaleDataScience', 'size': '2477'}