Numpy学习1

1.Numpy方法初探

>>> import numpy as np
>>> # Create a length-10 integer array filled with zeros
>>> np.zeros(10, dtype=int)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> # Create a 3x5 floating-point array filled with 1s
>>> np.ones((3, 5), dtype=float)
array([[1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.]])
>>> # Create a 3x5 array filled with 3.14
>>> np.full((3, 5), 3.14)
array([[3.14, 3.14, 3.14, 3.14, 3.14],
       [3.14, 3.14, 3.14, 3.14, 3.14],
       [3.14, 3.14, 3.14, 3.14, 3.14]])
>>> # Create an array filled with a linear sequence
>>> # Starting at 0, ending at 20, stepping by 2
>>> # (this is similar to the built-in range() function)
>>> np.arange(0, 20, 2)
array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])
>>> # Create an array of five values evenly spaced between 0 and 1
>>> np.linspace(0, 1, 5)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
>>> # Create a 3x3 array of uniformly distributed
>>> # random values between 0 and 1
>>> np.random.random((3, 3))
array([[0.79874333, 0.60991337, 0.29362395],
       [0.18324684, 0.09414009, 0.05824703],
       [0.67576864, 0.31021357, 0.97921232]])
>>> # Create a 3x3 array of normally distributed random values 
>>> # with mean 0 and standard deviation 1 均值0,方差1
>>> np.random.normal(0, 1, (3, 3))
array([[-0.92506352, -0.58967019,  0.72873444],
       [-0.50914721,  0.82898162, -0.93988454],
       [-1.91362691, -0.39273236, -0.19881052]])
>>> # Create a 3x3 array of random integers in the interval [0, 10)
>>> np.random.randint(0, 10, (3, 3))
array([[3, 3, 7],
       [6, 4, 0],
       [2, 2, 5]])
>>> # Create a 3x3 identity matrix 恒等方阵
>>> np.eye(3)
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])
>>> # Create an uninitialized array of three integers
>>> # The values will be whatever happens to already exist at that memory location
>>> np.empty(3)
array([1., 1., 1.])

numpy. empty ( shapedtype=floatorder='C' )

Return a new array of given shape and type, without initializing entries.

Parameters:

shape : int or tuple of int

Shape of the empty array

dtype : data-type, optional

Desired output data-type.

order : {‘C’, ‘F’}, optional

Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

Returns:

out : ndarray

Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None.











  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值