<jupyter_start><jupyter_text>$e^{A}\equiv \mathbb{I} + A + \frac{1}{2!}A^2 + \cdots$<jupyter_code>print(x)
y = np.random.random(5)*2-1.0
print(y)
print("arcsin(x) = ", np.arcsin(y)) 
print("arccos(x) = ", np.arccos(y)) 
print("arctan(x) = ", np.arctan(y))
print("x =", x)
print("e^x =",np.exp(x)) 
print("2^x =",np.exp2(x)) 
print("3^x =",np.power(3,x))
print("2.3^x = ",np.power(2.3,x))
## Homework: y^x, y and x both are float?

print("x =", x)
y = x + 0.2
print("ln(x) =", np.log(y)) 
print("log2(x) =", np.log2(y)) 
print("log10(x) =", np.log10(y))
## Homework: log_{3}(x) ?

print("x =", x)
print("exp(x) - 1 =", np.expm1(x)) ## What's this??
print("log(1 + x) =", np.log1p(x)) ## What's this??
from scipy import special
x=[1,5,10]
print("gamma(x) =", special.gamma(x)) 
print("ln|gamma(x)| =", special.gammaln(x)) 
print("beta(x, 2) =", special.beta(x, 2))
x = np.array([0, 0.3, 0.7, 1.0]) 
print("erf(x) =", special.erf(x)) 
print("erfc(x) =", special.erfc(x)) 
print("erfinv(x) =", special.erfinv(x))
x = np.arange(5)
y = np.empty(5) ## ??
print("x: ",x)
print("y: ", y)
print(np.multiply(x,10))
np.multiply(x, 10, out=y) 
print("y: ", y)

big_array = np.random.rand(1000000)
%timeit sum(big_array)
%timeit np.sum(big_array)
print(min(big_array))
print(max(big_array))
%timeit min(big_array)
%timeit np.min(big_array)
M = np.random.random((3, 4)) 
print(M)
M.sum()
N = np.matrix([[1,2],[3,4]])
print(N)
N.sum()
N.min()
N.min(axis=0)
NN = np.matrix([[1,3,5],[4,2,4]])
NN.min(axis=0)
NN.min(axis=1)
import numba as nb

@nb.jit(nopython=True)
def compute_reciprocals(values): 
    output = np.empty(len(values)) 
    for i in range(len(values)):
        output[i] = 1.0 / values[i] 
    return output
           
%timeit compute_reciprocals(big_array)
%timeit 1.0/big_array<jupyter_output><empty_output><jupyter_text>Comprehensive practice<jupyter_code>X = np.random.random((10, 3))
print(np.shape(X))
Xmean = X.mean(0)
print(Xmean)
X_centered = X - Xmean ## Homework: principle of this operation??
print(X_centered)
X_centered.mean(0)<jupyter_output><empty_output><jupyter_text>Example: heights of american presidents<jupyter_code>!head -4 "./PythonData/data/president_heights.csv"


import pandas as pd ## 
data = pd.read_csv('./PythonData/data/president_heights.csv') 
heights = np.array(data['height(cm)'])
print(heights)
print("Mean height: ", heights.mean()) 
print("Standard deviation:", heights.std())
print("Minimum height:    ", heights.min())
print("Maximum height:    ", heights.max())
print("25th percentile: ", np.percentile(heights, 25))
print("Median:          ", np.median(heights))
print("75th percentile: ", np.percentile(heights, 75))
import seaborn; seaborn.set() # set plot style


plt.hist(heights)
plt.title('Height Distribution of US Presidents')
plt.xlabel('height (cm)')
plt.ylabel('number');<jupyter_output><empty_output><jupyter_text>广播（Broadcasting）<jupyter_code># x and y have 50 steps from 0 to 5 
x = np.linspace(0, 5, 50)
print('x: ',x)
y = np.linspace(0, 5, 50)[:, np.newaxis] ## Homework: what is newaxis??
print('y: ',y)
z = np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)
## Homework: why z is (50,50) 'matrix'?
print(np.shape(z))
plt.imshow(z, origin='lower', extent=[0, 5, 0, 5],
                       cmap='viridis')
plt.colorbar();<jupyter_output><empty_output><jupyter_text>Example: counting of the rainy days<jupyter_code>import pandas as pd
# use Pandas to extract rainfall inches as a NumPy array
rainfall = pd.read_csv('./PythonData/data/Seattle2014.csv')['PRCP'].values 
inches = rainfall / 254 # 1/10mm -> inches
inches.shape
import seaborn; seaborn.set() # set plot styles
plt.hist(inches, 40);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21271393643031786, 'fraction_numerical': 0.03341483292583537, 'mean_word_length': 5.283276450511946, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '273198', 'license': 'MIT', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1552, 'n_words': 296, 'path': 'Tutorial2.ipynb', 'repo_name': 'yongleli/ComputPhys2020', 'size': '3681'}