import numpy as np
n = np.ones((3,4))
print("np.ones: ",n)
n=np.zeros((2,3,4),dtype=np.int16) print("np.zeros: ",n)
n=np.random.random((2,2)) print("random.random: ",n)
n=np.empty((3,2)) print("empty: ",n)
n=np.full((2,2),7) print("full: ",n)
n=np.arange(10,25,5) print("arange: ",n)
n=np.linspace(0,2,9) print("linspace: ",n)
n = np.eye(5) print("np.eye: ",n)
n = np.identity(5) print("np.identity: ",n)
nHIGH=np.eye(500) np.save('/home/silvio/testg',nHIGH) np.savetxt('/home/silvio/testg.txt',nHIGH) np.savez('/home/silvio/testH',nHIGH) np.savez_compressed('/home/silvio/testH-c',nHIGH)
!ls -l /home/silvio/testg.npy !ls -l /home/silvio/testH.npz !ls -l /home/silvio/testH-c.npz !cat /home/silvio/testg.npy
my_array2 = np.loadtxt('/home/silvio/testg.txt') print("my_array2: ",my_array2)
my_array2 = np.load('/home/silvio/testg.npy') #, skip_header=1, filling_values=-999)
print("my_array2: ",my_array2)
my_array2 = np.load('/home/silvio/testH-c.npz') #, skip_header=1, filling_values=-999)
print("my_array2: ",my_array2) print("my_array2: ",my_array2.files) print("my_array2: ",my_array2['arr_0']) my_array=np.full((12,12),70)
print(my_array.ndim)
print(my_array.size)
print(my_array.flags)
print(my_array.itemsize)
print(my_array.nbytes) np.savez('my_array',my_array)
x=np.random.random((3,4)) y=np.random.random((5,1,4))
res=np.add(x,y) print('res: ',res)
res2=res.sum() print('res2: ',res2)
my_2d_array=np.random.random((4,4))
print(my_2d_array[1][2])
print(my_2d_array[1,2])
-
grid = np.array([[1, 2, 3],[4, 5, 6]])
-
grid2 = np.array([[10, 20, 30],[40, 50, 60]])
-
np.concatenate([grid, grid2])
-
x = np.array([1, 2, 3])
-
grid = np.array([[9, 8, 7],[6, 5, 4]])
- np.vstack([x, grid])
- y = np.array([[99],[99]])
- np.hstack([grid, y])
- array([[ 0, 1, 2, 3],[ 4, 5, 6, 7],[ 8, 9, 10, 11],[12, 13, 14, 15]])
- upper, lower = np.vsplit(grid, [2])
- print(upper)
- print(lower)
-
Crie um array com 10 elementos usando a função arange
-
Transforme esse array de 1D (1x10) para 2D (2x5) usando a função reshape
-
Crie duas matrizes bidimensionais com valores aleatórios
-
calcule a transposta de cada matriz
-
multiplique as duas matrizes
-
Salve as matrizes de entrada e a de saída em arquivos. Qual o tamanho dos arquivos gerados?
-
Crie duas bidimensionais matrizes com valores aleatórios e gere uma única matriz combinando linha a linha