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。

  • 相关阅读:
    工业和信息化部“十二五”规划教材:阵列信号处理及MATLAB实现
    PHP 7从零基础到项目实战
    HTML+CSS网页设计详解
    新编 中文版Maya入门与提高
    Lua游戏AI开发指南
    这么设计能热卖:融入运营思维的电商设计进阶宝典(套装上下册)
    WCF初探-1:认识WCF
    用微信二维码登录自己的网站
    01-C语言基本知识
    「OC」内存管理
  • 原文地址:https://www.cnblogs.com/peterleee/p/9373755.html
Copyright © 2011-2022 走看看