<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Garimpagem de Dados
Aula 2 - NumPy
06/10/2017
Step1:  Exercícios
Como calcular o tamanho da memória usada de qualquer array?
Crie a matriz 3x3 com valores em um range de 0 a 8
Crie um vetor randômico de tamanho 30 e calcule a média
<ASSISTANT_TASK:>
Python Code:
import numpy as np
a = np.array([1, 2, 3])
print(a)
print('')
b = np.array([(1, 2, 3), (4, 5, 6)])
print(b)
a + b
a * b
b - a
a**2
10*np.sin(a) # seno trigonométrico
b<35
print('Axis 1: %s' % b[0])
print(np.average(b))
print(b.sum())
print(b.min())
print(b.max())
b.sum(axis=0) # sum of each column
b.min(axis=1) # min of each row
b.cumsum(axis=1) # cumulative sum along each row
a = np.zeros((3, 5))
print(a)
np.ones((2,3,4), dtype=np.int16) # dtype can also be specified
np.empty([2,3]) # uninitialized, output may vary
c = np.full(5, 2, dtype=np.float)
print(c)
d = np.full((2, 2), 10)
print(d)
np.arange(10, 30, 5)
np.arange(0, 2, 0.3) # it accepts float arguments
c = np.random.rand(2, 3)
print(c)
np.transpose(c)
d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(d)
d[:, 0]
d[:, 1]
d[:, 0:2]
d[:, 2]
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # start:stop:step
np.save('/tmp/x.npy', x)
del(x)
x = np.load('/tmp/x.npy')
print(x)
# Usar memory mapping quando o conteúdo não couber em memória RAM
x_mm = np.memmap('x_mm.npy', dtype='float32', mode='w+', shape=(1000, 100))
x_mm[999][99] = 12.5
print(x_mm[999][99])
# Delete the memmap instance to close the file (the mmap file is not deleted). 
# Deletion flushes memory changes to disk before removing the object.
del(x_mm)
# Load
x_mm = np.memmap('x_mm.npy', dtype='float32', mode='r', shape=(1000, 100))
print(x_mm[999][99])
Explanation: Garimpagem de Dados
Aula 2 - NumPy
06/10/2017
End of explanation
#1
t = np.zeros((10, 10))
print('%d bytes' % (t.size * t.itemsize))
#2
f = np.arange(9).reshape(3,3)
print(f)
#3
z = np.random.random(30)
print(z)
print(z.mean())
Explanation: Exercícios
Como calcular o tamanho da memória usada de qualquer array?
Crie a matriz 3x3 com valores em um range de 0 a 8
Crie um vetor randômico de tamanho 30 e calcule a média
End of explanation
<END_TASK>