zoukankan      html  css  js  c++  java
  • 2-8 四则运算

    In [2]:
    import numpy as np
    x=np.array([5,5])
    y=np.array([2,2])
    
     

    乘法

    In [3]:
    np.multiply(x,y)
    
    Out[3]:
    array([10, 10])
    In [4]:
    np.dot(x,y)#内积
    
    Out[4]:
    20
    In [5]:
    x.shape
    
    Out[5]:
    (2,)
    In [6]:
    y.shape
    
    Out[6]:
    (2,)
    In [7]:
    x.shape=2,1
    x
    
    Out[7]:
    array([[5],
           [5]])
    In [8]:
    np.dot(x,y)#维度不一样
    
     
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-8-6849a5f7ad6c> in <module>()
    ----> 1np.dot(x,y)
    
    ValueError: shapes (2,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)
    In [9]:
    y.shape=1,2
    y
    
    Out[9]:
    array([[2, 2]])
    In [10]:
    x
    
    Out[10]:
    array([[5],
           [5]])
    In [12]:
    print(x.shape)
    print(y.shape)
    
     
    (2, 1)
    (1, 2)
    
    In [14]:
    np.dot(x,y)
    
    Out[14]:
    array([[10, 10],
           [10, 10]])
    In [15]:
    np.dot(y,x)
    
    Out[15]:
    array([[20]])
    In [17]:
    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 [18]:
    x=np.array([1,1,1])
    y=np.array([1,1,1])
    x==y#必须维度一样,逐一进行比较
    
    Out[18]:
    array([ True,  True,  True])
    In [19]:
    np.logical_and(x,y)#逻辑与操作
    
    Out[19]:
    array([ True,  True,  True])
    In [20]:
    np.logical_or(x,y)#或
    
    Out[20]:
    array([ True,  True,  True])
    In [21]:
    np.logical_not(x,y)#非
    
    Out[21]:
    array([0, 0, 0])
  • 相关阅读:
    任意代码执行实例
    任意代码执行漏洞
    Port Hacking
    任意命令执行漏洞
    sql注入基于错误-单引号-字符型
    与SQL注入第一次相遇
    Hibernate基础知识
    TxQueryRunner类对结果集封装成bean、map及object的操作
    map的数据创建任意类的JavaBean对象
    UUID产生的JAR
  • 原文地址:https://www.cnblogs.com/AI-robort/p/11627176.html
Copyright © 2011-2022 走看看