• 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

  • 相关阅读:
    tornado web 框架的认识
    JavaScript 作用域知识点梳理
    服务器
    git——学习
    webservice——和API接口
    celery——任务调度模块
    supervisor——进程管理工具
    Python常用的语句
    数据类型比较总结
    字符集和字符编码问题
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12844962.html
Copyright © 2020-2023  润新知