ML#0.1 NumPy Basics Arrays and Vectorized Computation
注意
本章大篇幅引用Pyhon for Data Analysis,Third Edition,Wes McKinney,仅作为学习交流使用。
本章默认进行如下操作:
import numpy as np
import pandas as pd
NumPy Basics: Arrays and Vectorized Computation
NumPy, short for Numerical Python, is one of the most important foundational packages for numerical computing in Python.
The NumPy ndarray: A Multidimensional Array Object
Creating ndarrays:arr1 = np.array(data1)
1 | In [22]: data2 = [[1, 2, 3, 4], [5, 6, 7, 8]] |
0s,1s,Trues:
1 | np.zeros(10) |
Data Types for ndarrays
1 | In [33]: arr1 = np.array([1, 2, 3], dtype=np.float64) |
Indexing and Slicing
Boolean Indexing
1 | In [100]: names = np.array(["Bob", "Joe", "Will", "Bob", "Will", "Joe", "Joe"]) |
Fancy Indexing
1 | In [120]: arr = np.zeros((8, 4)) |
Pseudorandom Number Generation
引用自:NumPy random number generator methods
Numpy.Random API reference:https://numpy.org/doc/stable/reference/random/index.html
| Method | Description |
|---|---|
| permutation | Return a random permutation of a sequence, or return a permuted range |
| shuffle | Randomly permute a sequence in place |
| uniform | Draw samples from a uniform distribution |
| integers | Draw random integers from a given low-to-high range |
| standard_normal | Draw samples from a normal distribution with mean 0 and standard deviation 1 |
| binomial | Draw samples from a binomial distribution |
| normal | Draw samples from a normal (Gaussian) distribution |
| beta | Draw samples from a beta distribution |
| chisquare | Draw samples from a chi-square distribution |
| gamma | Draw samples from a gamma distribution |
| uniform | Draw samples from a uniform [0, 1) distribution |
Universal Functions
Numpy API reference:https://numpy.org/doc/stable/reference/ufuncs.html
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 TheValuePoint's Blog!
