<jupyter_start><jupyter_text>Basic Functions  imports<jupyter_code>import numpy as np
from numpy import linspace, arange, r_, logspace, array, log10, around, \
    ceil, floor, cumsum, diff, exp, sort, absolute, logical_not, nansum, \
    union1d, in1d, intersect1d, nan, isnan, log, hstack    
from numpy.random import randn<jupyter_output><empty_output><jupyter_text>Exercise 1<jupyter_code>print("linspace(0,10,11):")
linspace(0,10,11)
print("arange(11):")
arange(11)
print("r_[0:11]:")
r_[0:11]

print("linspace(4,13,10):")
linspace(4,13,10)
print("arange(4,14):")
arange(4,14)
print("r_[4:14]:")
r_[4:14]
print("linspace(0,1,5):")
linspace(0,1,5)
print("arange(0,1.01,.25):")
arange(0,1.01,.25)
print("r_[0:1:5j]:")
r_[0:1:5j]

print("linspace(0,-5,5):")
linspace(0,-5,5)
print("arange(0,-6,-1):")
arange(0,-6,-1)
print("r_[0:-6:-1]:")
r_[0:-6:-1]
## Exercise 2
print("logspace(0,2,21) :")
logspace(0,2,21)
print("10**linspace(0,2,21):")
10**linspace(0,2,21)
print("linspace(2,10,51):")
linspace(2,10,51)
print("log10(logspace(2,10,51)):")
log10(logspace(2,10,51))<jupyter_output><empty_output><jupyter_text>Exercise 3<jupyter_code>y=array([0,0.5,1.5,2.5,1.0,1.0001,-0.5,-1,-1.5,-2.5])
y
print("y.round():")
y.round()
print("around(y):")
around(y)
print("ceil(y):")
ceil(y)
print("floor(y):")
floor(y)<jupyter_output><empty_output><jupyter_text>Exercise 4<jupyter_code>n=10
y = arange(n+1)
print("cumsum(y):")
cumsum(y)
print("y*(y+1)/2:")
y*(y+1)/2<jupyter_output><empty_output><jupyter_text>Exercise 5<jupyter_code>x = randn(20)
y = cumsum(x)
print("y[19]:")
y[19]
print("sum(x):")
sum(x)<jupyter_output><empty_output><jupyter_text>Exercise 6The naive version is missing one value. The solution is to add a leading 0.<jupyter_code>x = randn(10)
y = cumsum(x)
z = hstack((0,y))
print("diff(z):")
diff(z)<jupyter_output><empty_output><jupyter_text>Exercise 7<jupyter_code>print("exp(array([log(0.5),log(1),log(np.e)])):")
exp(array([log(0.5),log(1),log(np.e)]))<jupyter_output><empty_output><jupyter_text>Exercise 8<jupyter_code>print("absolute(array([0.0,-3.14,3+4j])):")
absolute(array([0.0,-3.14,3+4j]))<jupyter_output><empty_output><jupyter_text>Exercise 9<jupyter_code>x = array([-4,2,-9,-8,10])
print("x:")
x
print("x.sort():")
x.sort()
print("x:")
x<jupyter_output><empty_output><jupyter_text>Exercise 10<jupyter_code>print("x.max():")
x.max()
i = x.argmax()
i
print("x[i]:")
x[i]<jupyter_output><empty_output><jupyter_text>Exercise 11a<jupyter_code>x = array([1,2,3,4,5])
y = array([1,2,4,6])
print("y[logical_not(in1d(y,intersect1d(x,y)))]:")
y[logical_not(in1d(y,intersect1d(x,y)))]<jupyter_output><empty_output><jupyter_text>Exercise 11b<jupyter_code>z=union1d(x,y)
z
print("z[logical_not(in1d(z,intersect1d(x,y)))]:")
z[logical_not(in1d(z,intersect1d(x,y)))]
y = array([nan,2.2,3.9,4.6,nan,2.4,6.1,1.8])
y
T = sum(logical_not(isnan(y)))
T<jupyter_output><empty_output><jupyter_text>Exercise 12<jupyter_code>Ey2=nansum(y**2)/T
Ey =nansum(y)/T
nanvar = Ey2-Ey**2
nanvar<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.24087591240875914, 'fraction_numerical': 0.0822826808228268, 'mean_word_length': 10.964285714285714, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '130694', 'license': 'CC0-1.0', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1486, 'n_words': 158, 'path': 'solutions/chapter05/basic_functions.ipynb', 'repo_name': 'ColdTeapot273K/python-for-econometrics-statistics-data-analysis', 'size': '3014'}