zoukankan      html  css  js  c++  java
  • numpy 小示例

    import numpy as np 

    生成 3*4 的由  0 组成的二维数组

    >>> np.zeros((3,4))

    array([[0., 0., 0., 0.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.]])

    生成  2*3*4   的由  1 组成的三维数组

    >>>np.ones((2,3,4),dtype=np.int16)

    array([[[1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1]],

    [[1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1]]], dtype=int16)

    生成 10 ~25 间的 间隔为5的数列

    >>>np.arange(10,25,5)

    array([10, 15, 20])

    生成 0~2间的等差数列,元素个数 为 9 

    >>>np.linspace(0,2,9)

    array([0.  , 0.25, 0.5 , 0.75, 1.  , 1.25, 1.5 , 1.75, 2.  ])

    以给定数 7 ,生成 指定形状2*2的矩阵 

    >>> np.full((2,2),7)
    array([[7, 7],
    [7, 7]])

    生成对角矩阵, 长与宽相等 ,默认中间对角线(左上到右下)全是1,其余为0

    >>np.eye(2)

    array([[1., 0.],
    [0., 1.]])

    生成数值在1以内的指定形状 2*2 的随机矩阵

    >>> np.random.random((2,2))
    array([[0.36248815, 0.60881839],
    [0.10805521, 0.92618553]])

     

    生成指定形状的空数组,数组内数据,可能是随机的

    empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. On the other hand, it requires the user to manually set all the values in the array, and should be used with caution.

    >>np.empty((3,2))

    array([[1.39069238e-309, 1.39069238e-309],
    [1.39069238e-309, 1.39069238e-309],
    [1.39069238e-309, 1.39069238e-309]])

     

  • 相关阅读:
    性能测试总结(三)--工具选型篇
    什么是性能瓶颈
    基于Linux服务器的性能分析与优化
    常见的APP性能测试指标
    性能测试方案设计的方法和思路
    测试渐进式
    Selenium2Library关键字
    互联网运营工作四大内容
    RF学习过程中遇到的问题
    Robot Framework自动化测试环境的搭建
  • 原文地址:https://www.cnblogs.com/Ting-light/p/9210279.html
Copyright © 2011-2022 走看看