zoukankan      html  css  js  c++  java
  • numpy-ufunc函数

    import numpy as np
    
    x = np.linspace(0, 2 * np.pi, 10)
    t = np.sin(x, out=x)
    print('x;  ', x)  # 值存到了x里面
    """
    运 算 符  对应的ufunc 函数
    y = x1 + x2  add(x1, x2 [, y])
    y = x1 - x2  subtract(x1, x2 [, y])
    y = x1 * x2  multiply (x1, x2 [, y])
    y = x1 / x2  divide (x1, x2 [, y]), 如果两个数组的元素为整数,那么用整数除法
    y = x1 / x2  true_divide (x1, x2 [, y]), 总是返回精确的商
    y = x1 // x2  floor_divide (x1, x2 [, y]), 总是对返回值取整
    y = -x  negative(x [,y])
    y = x1**x2  power(x1, x2 [, y])
    y = x1 % x2  remainder(x1, x2 [, y]),或 mod(x1, x2, [, y])
    """
    a = np.arange(0, 4)
    b = np.arange(1, 5)
    print("np.add(a,b,a):   
    ", np.add(a, b, a))
    print("a:  
    ", a)
    """
    np.add(a,b,a):   
     [1 3 5 7]
    a:  
     [1 3 5 7]
    """
    
    """
    比较运算符  ufunc 函数
    y = x1 == x2  equal(x1, x2 [, y])
    y = x1 != x2  not_equal(x1, x2 [, y])
    y = x1 < x2  less(x1, x2, [, y])
    y = x1 <= x2  less_equal(x1, x2, [, y])
    y = x1 > x2  greater(x1, x2, [, y])
    y = x1 >= x2  greater_equal(x1, x2, [, y])
    """
    a = np.array([1, 2, 3, 4, 5])
    b = np.array([1, 1, 2, 4, 5])
    print("a>b:   
    ", a > b)
    print("np.greater(a,b,a):  
    ", np.greater(a, b, a))
    print("a:  
    ", a)
    """
    a>b:   
     [False  True  True False False]
    np.greater(a,b,a):  
     [0 1 1 0 0]
    a:  
     [0 1 1 0 0]
    """
    # np.logical_and np.logical_not np.logical_or np.logical_xor
    a = np.array([1, 2, 3, 4, 5])
    b = np.array([1, 1, 2, 4, 5])
    print("np.logical_or(a==b, a>b):  
    ", np.logical_or(a < b, a > b))  # a!=b
    """
    np.logical_or(a==b, a>b):  
     [False  True  True False False]
    """
    

    可以使用数组的 any()或 all()方法。只要数组中有一个值为True,any()就返回True;而只有当数组的全部元素都为True 时,all()才返回True。

  • 相关阅读:
    Handler使用总结(转)
    LR连接oracle数据库-lr_db_connect
    selenium2(WebDriver)环境搭建
    使用selenium控制滚动条(非整屏body)
    selenium-打开IE浏览器遇到问题记录
    使用re-sign.jar对apk进行重签名
    Robotium-无源码测试
    genymotion不能联网
    SQL 常用脚本
    todolist
  • 原文地址:https://www.cnblogs.com/peterleee/p/9373755.html
Copyright © 2011-2022 走看看