day1-7-numpy运算
In [1]:
import numpy as np
In [2]:
x = np.array([5,5])
y = np.array([2,2])
In [3]:
np.multiply(x,y)
Out[3]:
array([10, 10])
In [4]:
x
Out[4]:
array([5, 5])
In [5]:
y
Out[5]:
array([2, 2])
In [6]:
np.dot(x,y) #对应求积 再把积相加
Out[6]:
20
In [7]:
x.shape
y.shape
x.shape = 2,1
np.dot(x,y)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-c265ae669615> in <module>
2 y.shape
3 x.shape = 2,1
----> 4 np.dot(x,y)
<__array_function__ internals> in dot(*args, **kwargs)
ValueError: shapes (2,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)
In [8]:
y.shape = 1,2
y
Out[8]:
array([[2, 2]])
In [9]:
x
Out[9]:
array([[5],
[5]])
In [10]:
print (x.shape)
print (y.shape)
(2, 1) (1, 2)
In [13]:
np.dot(y,x)
Out[13]:
array([ 6, 15])
In [11]:
np.dot(x,y)
Out[11]:
array([[10, 10],
[10, 10]])
In [12]:
x = np.array([1,1,1])
y = np.array([[1,2,3],[4,5,6]])
print (x * y)
[[1 2 3] [4 5 6]]
In [14]:
y = np.array([1,1,1,4])
x = np.array([1,1,1,2])
x == y
Out[14]:
array([ True, True, True, False])
In [15]:
np.logical_and(x,y)
Out[15]:
array([ True, True, True, True])
In [16]:
np.logical_or(x,y)
Out[16]:
array([ True, True, True, True])
In [17]:
np.logical_not(x,y)
Out[17]:
array([0, 0, 0, 0])
In [ ]:

浙公网安备 33010602011771号