organizada
de representar os dados numéricos.tamanho
ou a dimensão
da matriz (nro linhas) X (nro colunas), por exemplo $2x3$
In [1]:
import numpy as np # for array, dot and so on
In [53]:
B = np.arange(9).reshape(3, 3)
print(B)
In [54]:
A = np.array([
[-1, 42, 10],
[12, 0, 9]
])
print(A)
In [55]:
# inspecting the matrices
print(A.shape) # 2 x 3
print(B.shape) # 3 x 3
In [56]:
# We have 2 dimensions `X1` and `X2`
print(A.ndim)
print(B.ndim)
In [57]:
Zeros = np.zeros((2, 3))
print(Zeros)
In [58]:
Ones = np.ones((3, 3))
print(Ones)
In [59]:
Empty = np.empty((4, 4))
print(Empty)
In [9]:
print(np.arange(5, 30, 7))
In [10]:
print(np.arange(10, 13, .3))
In [11]:
print(np.linspace(0, 2, 13))
In [12]:
print(np.arange(10000))
In [13]:
print(np.arange(10000).reshape(100,100))
In [61]:
A = np.array([10, 20, 30, 40, 50, -1])
B = np.linspace(0, 1, A.size)
print("{} + {} -> {}".format(A, B, A + B))
print("{} - {} -> {}".format(A, B, A - B))
In [62]:
print("{} ** 2 -> {}".format(A, A ** 2))
In [64]:
print("2 * sin({}) -> {}".format(A, 2 * np.sin(A)))
In [67]:
print(A > 30)
In [68]:
print(A[A > 30])
In [19]:
print("{} * {} -> {}".format(A, B, A * B))
In [20]:
print("{}.{} -> {}".format(A, B, A.dot(B)))
In [21]:
print("{}.{} -> {}".format(A, B, np.dot(A, B)))
In [22]:
print(np.ones(10) * 12)
In [23]:
M = np.linspace(-1, 1, 16).reshape(4, 4)
print(M)
In [24]:
print("sum(A) -> {}".format(M.sum()))
In [25]:
print("max(A) -> {} | min(A) -> {}" .format(M.max(), M.min()))
In [26]:
N = np.arange(16).reshape(4, 4)
print(N)
In [27]:
print(N.sum(axis=0)) # sum by column
In [28]:
print(N.sum(axis=1)) #sum by row
In [29]:
print(N.min(axis=1))
In [30]:
print(N.cumsum(axis=0))
In [31]:
print(N)
In [32]:
for column in range(N.shape[1]):
print(N[:,column])
In [33]:
print(N.T)
In [34]:
print(N)
In [35]:
print(N.transpose())
In [36]:
print(N)
In [37]:
I = np.eye(2)
print(I)
In [38]:
I2 = I * 2
I2_inv = np.linalg.inv(I2)
print(I2_inv)
In [39]:
print(np.dot(I2, I2_inv))
In [40]:
dir(np.linalg)
Out[40]:
In [41]:
print(np.trace(I2))
In [42]:
Prod = np.dot(I2, I2)
print(Prod)
In [43]:
print(np.linalg.eig(Prod))
In [44]:
A = np.linspace(1, 4, 4).reshape(2, 2)
print(A)
In [45]:
y = np.array([5., 7.])
In [46]:
x = np.linalg.solve(A, y)
print(x)
In [47]:
print(np.dot(A, x.T))
In [48]:
x = np.arange(0, 10, 2)
y = np.arange(5)
print(np.vstack([x, y]))
In [49]:
print(np.hstack([x, y]))
In [50]:
print(np.hsplit(x, [2]))
In [51]:
print(np.hsplit(x, [2, 4]))
In [52]:
print(np.vsplit(np.eye(3), range(1, 3)))
In [ ]:
In [ ]: