• 05.其他创建numpy数组的方法


    >>> import numpy as np
    >>> np.zeros(10,dtype=int)
    array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    >>> np.zeros((3,5)) array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]])
    >>> np.zeros(shape=(3,5),dtype=int) array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
    >>> np.ones(10) array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
    >>> np.ones((3,5)) array([[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]])
    >>> np.full(shape=(3,5),fill_value=666) array([[666, 666, 666, 666, 666], [666, 666, 666, 666, 666], [666, 666, 666, 666, 666]])
    >>> [i for i in range(0,20,2)] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
    >>> np.arange(0,20,2) array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
    >>> np.arange(0,1,0.2) array([0. , 0.2, 0.4, 0.6, 0.8])
    >>> np.linspace(0,20,10) array([ 0. , 2.22222222, 4.44444444, 6.66666667, 8.88888889, 11.11111111, 13.33333333, 15.55555556, 17.77777778, 20. ])
    >>> np.linspace(0,20,11) array([ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20.])
    >>> np.random.randint(10) 0
    >>> np.random.randint(0,10,10) array([1, 4, 7, 9, 0, 6, 1, 5, 2, 6])
    >>> np.random.randint(2,10,size=10) array([3, 3, 8, 9, 4, 3, 2, 7, 2, 4])
    >>> np.random.randint(2,10,size=(3, 5)) array([[9, 8, 4, 2, 3], [6, 3, 5, 8, 6], [7, 8, 6, 7, 9]])
    >>> np.random.seed(666) >>> np.random.randint(2,10,size=(3, 5)) array([[6, 4, 7, 8, 8], [8, 3, 8, 6, 7], [5, 8, 5, 6, 9]])
    >>> np.random.randint(2,10,size=(3, 5)) array([[6, 8, 3, 9, 2], [8, 2, 9, 7, 4], [6, 9, 7, 7, 7]])
    >>> np.random.random() 0.7744794542685887
    >>> np.random.random(10) array([0.00510884, 0.11285765, 0.11095367, 0.24766823, 0.0232363 , 0.72732115, 0.34003494, 0.19750316, 0.90917959, 0.97834699])
    >>> np.random.random((3, 5)) array([[0.53280254, 0.25913185, 0.58381262, 0.32569065, 0.88889931], [0.62640453, 0.81887369, 0.54734542, 0.41671201, 0.74304719], [0.36959638, 0.07516654, 0.77519298, 0.21940924, 0.07934213]])
    >>> np.random.normal(10,100) -110.99026554923134
  • 相关阅读:
    5月14日 游戏闯关,
    无名管道练习小程序
    关于对进程、线程的返回状态的获取的理解
    C语言中内存分布及程序运行中(BSS段、数据段、代码段、堆栈)
    linux 与会话相关的一些概念、登录过程
    linux进程——fork、vfork 两函数的实现及两者区别
    关于 linux 中init 进程
    linux进程——fork()函数
    linux下 vim多屏幕操作
    linux下进程管理
  • 原文地址:https://www.cnblogs.com/waterr/p/14032551.html
Copyright © 2020-2023  润新知