numpy学习笔记
In [4]:
import numpy as np
my_list = [1,2,3]
x = np.array(my_list)
print('列表',my_list)
print('Array:',x)
In [5]:
np.array([1,2,3])-np.array([4,5,6])
Out[5]:
In [9]:
my_list = [[1,2,3],[4,5,6]]
x = np.array(my_list)
print(x)
print("x's shape is : ",x.shape)
In [10]:
list = np.arange(0,30,2)
print(list)
In [12]:
new_array = list.reshape(3,5)
print(new_array)
In [18]:
x
print('ones:\n',np.ones((3,2)))
print('zeros:\n',np.zeros((3,2)))
print('eye:\n',np.eye((3)))
print('diag:\n',np.diag((1,2,3)))
print('diag:\n',np.diag(my_list))
In [20]:
x=np.arange(16).reshape((4,4))
print(x)
In [21]:
x
print('diag:\n',np.diag(x,1))
print('diag:\n',np.diag(x,-1))
In [22]:
print('diag:\n',np.diag(x,2))
print('diag:\n',np.diag(x,-2))
In [23]:
x
print("*操作:\n",np.array([1,2,3]*3))
print("*操作:\n",np.repeat([1,2,3],3))
In [25]:
p1 = np.ones((3,3))
p2 = np.arange(9).reshape(3,3)
print("纵向+\n",np.vstack((p1,p2)))
print("横向+\n",np.hstack((p1,p2)))
In [27]:
print('p1 + p2 \n',p1+p2)
print('p1 * p2 \n',p1*p2)
print('p2^2 \n',p2**2)
print('p1 . p2 \n',p1.dot(p2))
In [ ]: