zoukankan      html  css  js  c++  java
  • Numpy数组的函数

    import numpy as np
    # 将 0~100 10等分
    x = np.arange(0,100,10)
    # array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
    
    # 每个数组元素对应的正弦值
    np.sin(x)
    '''
    array([ 0.        , -0.54402111,  0.91294525, -0.98803162,  0.74511316,
           -0.26237485, -0.30481062,  0.77389068, -0.99388865,  0.89399666])
    '''
    # 每个数组元素对应的余弦值
    np.cos(x)
    '''
    array([ 1.        , -0.83907153,  0.40808206,  0.15425145, -0.66693806,
            0.96496603, -0.95241298,  0.6333192 , -0.11038724, -0.44807362])
    '''
    # 对参数进行四舍五入
    np.round(np.cos(x))
    # array([ 1., -1.,  0.,  0., -1.,  1., -1.,  1., -0., -0.])
    
    # 对参数进行上入整数 3.3->4
    np.ceil(x/3)
    # array([ 0.,  4.,  7., 10., 14., 17., 20., 24., 27., 30.])
    
    
    # 分段函数
    x = np.random.randint(0,10,size=(1,10))
    # array([[0, 3, 6, 7, 9, 4, 9, 8, 1, 8]])
    
    # 大于 4 的置为 0
    np.where(x > 4,0,1)
    # array([[1, 1, 0, 0, 0, 1, 0, 0, 1, 0]])
    
    # 小于 4 的乘 2 ,大于 7 的乘3
    np.piecewise(x,[x<4,x>7],[lambda x:x*2,lambda x:x*3])
    # array([[ 0,  6,  0,  0, 27,  0, 27, 24,  2, 24]])

    2020-05-07

  • 相关阅读:
    OS-lab4
    OS-lab3
    OS-lab2
    OS-lab1
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    HTTP_POST
    实习日志1(2020.7.27-2020.9.31)
    Web app ------ 从Servlet读取Json数据并显示,生成历史数据曲线图
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12844962.html
Copyright © 2011-2022 走看看