<jupyter_start><jupyter_text>Introdução e prelinares Até a pg 61<jupyter_code>import mxnet as mx
from mxnet import np, npx
npx.set_np()
x=np.arange(12)
x,type(x)
x.shape
x.size
x=x.reshape(3,4)
x
X=np.arange(12).reshape(3,4)
Y=np.array([[2,1,4,3], [1,2,3,4], [4,3,2,1]])
X
Y
np.concatenate([X, Y], axis=0), np.concatenate([X, Y], axis=1)
X==Y
x=np.array([1,2,3]).reshape(3,1)
x
y=np.array([1,2]).reshape(1,2)
y
x+y
X,Y
X[-1]
X[1:3]
X[0:3, 1:3]=13
X
X>Y,X,Y
T1 = np.arange(12).reshape(1, 6, 2)
T1,np.arange(12)
T2 = np.ones(shape=(6,6,1))
T2<jupyter_output><empty_output><jupyter_text>Data  Preprocessing pg 51<jupyter_code>import os
os.makedirs(os.path.join('../../data','tmp'), exist_ok=True)
data_file=os.path.join('../../data','tmp','house_tiny.csv')
with open(data_file,'w') as f:
    f.write('NumRooms,Alley,Price\n') # Column names
    f.write('NA,Pave,127500\n') # Each row represents a data example
    f.write('2,NA,106000\n')
    f.write('4,NA,178100\n')
    f.write('NA,NA,140000\n')
import pandas as pd
data=pd.read_csv(data_file)
print(data)
inputs, outputs=data.iloc[:,0:2], data.iloc[:,2]
print(inputs)
inputs=inputs.fillna(inputs.mean())
print(inputs)
inputs=pd.get_dummies(inputs, dummy_na=True)
print(inputs)
X, y=np.array(inputs.values), np.array(outputs.values)
X, y<jupyter_output><empty_output><jupyter_text>fazer exercicios da pg 53<jupyter_code>t3=np.random.choice(np.array([1,2,np.nan]), (20, 5),p=np.array([0.4,0.4, 0.3]))
t3
df=pd.DataFrame(t3.asnumpy(),columns=['a','b','c','e','f'])
print(df)
df.isnull().mean()
df.columns[df.isnull().mean() < 0.25]
res1=df[df.columns[df.isnull().mean() < 0.25]]
print(res1)
resInput=np.array(res1.values)
resOutput=np.random.rand(20)
resInput,resOutput<jupyter_output><empty_output><jupyter_text>Linear Algebrapg 53<jupyter_code>A=np.arange(20).reshape(5,4)
A,A.mean(axis=0),A.mean(axis=1)
A.sum(),A.sum(axis=1),A.sum(axis=1,keepdims=True)
A/A.sum(axis=1,keepdims=True),A.cumsum(axis=1)<jupyter_output><empty_output><jupyter_text>Produto Hadamard (Element-wise) e Produto de Matriz           *                               dot<jupyter_code>A1=np.array([1,2,3,4]).reshape(2,2)
B1=np.array([-1,3,4,2]).reshape(2,2)
A1,B1,A1*B1,np.dot(A1,B1),np.dot(B1,A1)
A1=np.array([1,2,3,4])
B1=np.array([-1,3,4,2])
A1,B1,A1*B1,np.dot(A1,B1)
y=np.ones(4)
x.reshape(1,3), y<jupyter_output><empty_output><jupyter_text>Norm pg 63   - norma vetorial  Norm L2\[3,-4]sqrt{3² + -4²}=5<jupyter_code>u=np.array([3,-4])
u,np.linalg.norm(u)<jupyter_output><empty_output><jupyter_text>Norm L1\[3,-4]|3|+|-4|=7<jupyter_code>np.abs(u).sum()<jupyter_output><empty_output><jupyter_text>Frobenius norm Aplica a L2 sobre Matrizes  Exercícios pg 65 Confrontar com https://hy38.github.io/D2L-2-linear-algebra  1. Prove that the transpose of a matrix A’s transpose is A : (𝐀T)⊤=A(𝐀^T)^⊤ = A(AT)⊤=A<jupyter_code>A=np.arange(25).reshape(5,5)
AT=A.T
TA=AT.T
res=(A==TA).reshape(A.size)
#type(res),type(res.asnumpy()),
#np.diff(res,prepend=False, append=False)
np.count_nonzero(res%2==1)==A.size<jupyter_output>WARNING:root:np.count_nonzero is a fallback operator, which is actually using official numpy's implementation.<jupyter_text>2. Given two matrices A and B, show that the sum of transposes is equal to the transpose of a sum: A⊤+B⊤= (A+B)⊤<jupyter_code>A1=np.array([1,2,3,4,5,6,7,8,9]).reshape(3,3)
A2=A1.copy()
B1=np.array([2,4,6,8,10,12,14,16,18]).reshape(3,3)
B2=B1.copy()
A1,A2,B1,B2
R1=A1.T + B1.T
R2=(A1+B1).T
res=(R1==R2).reshape(R1.size)
np.count_nonzero(res%2==1)==R1.size<jupyter_output><empty_output><jupyter_text>3. Given any square matrixA, is A+A⊤ always symmetric? Why?<jupyter_code>t1=A1+A1.T
t2=B1+B1.T
res1=(t1==t1.T).reshape(t1.size)
res2=(t2==t2.T).reshape(t2.size)
res1,res2
np.count_nonzero(res1%2==1)==res1.size , np.count_nonzero(res2%2==1)==res2.size<jupyter_output><empty_output><jupyter_text>4. We defined the tensorX of shape (2, 3, 4) in this section. What is the output oflen(X)?<jupyter_code>T=np.ones((2,3,4))
T,T.size,T.shape<jupyter_output><empty_output><jupyter_text>5. For a tensorXof arbitrary shape, does len(X) always correspond to the length of a certain axis ofX? What is that axis?first  6.Run A / A.sum(axis=1) and see what happens. Can you analyze the reason?<jupyter_code>t=A.sum(axis=1)
A,t,A/t<jupyter_output><empty_output><jupyter_text>8. Consider a tensor with shape (2, 3, 4). What are the shapes of the summation outputs alongaxis 0, 1, and 2?<jupyter_code>A=mx.nd.arange(1,25).reshape(2,3,4)
A,A.sum(0),A.sum(1),A.sum(2)<jupyter_output><empty_output><jupyter_text>9. Feed a tensor with 3 or more axes to the linalg.norm function and observe its output. Whatdoes this function compute for tensors of arbitrary shape?https://www.educative.io/edpresso/what-is-the-nplinalgnorm-method-in-numpy<jupyter_code>A=(np.arange(24)-5).reshape(2,3,4)
A , np.linalg.norm(A),np.linalg.norm(A,axis=0),np.linalg.norm(A,axis=1),np.linalg.norm(A,axis=2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20109135004042036, 'fraction_numerical': 0.06265157639450283, 'mean_word_length': 6.830696202531645, 'pattern_counts': {'":': 0, '<': 58, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '449018', 'license': 'MIT', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2350, 'n_words': 338, 'path': 'notebooks/dl2/Cap 2 - Preliminares 1.ipynb', 'repo_name': 'lucmertins/CapDeepLearningBook', 'size': '4948'}