numpy重新学习系列(10)---如何用np.arange生成均匀间隔分布的array

简介: numpy重新学习系列(10)---如何用np.arange生成均匀间隔分布的array

   '''

   numpy.arange

   numpy.arange([start, ]stop, [step, ]dtype=None)

   Return evenly spaced values within a given interval.

   Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.

   When using a non-integer step, such as 0.1, the results will often not be consistent. It is better to use numpy.linspace for these cases.

   Parameters

   start  number, optional

   Start of interval. The interval includes this value. The default start value is 0.

   stop  number

   End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out.

   step  number, optional

   Spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified as a position argument, start must also be given.

   dtype dtype

   The type of the output array. If dtype is not given, infer the data type from the other input arguments.

   Returns

   arangend array

   Array of evenly spaced values.

   For floating point arguments, the length of the result is ceil((stop - start)/step). Because of floating point overflow, this rule may result in the last element of out being greater than stop.

   '''


    # 作用是返回均匀分布的array,从开始到结束的数字,按照step的间隔


   # 1. 生成规则是按照从start的数字开始,但是不包含stop的数字


   # 2. 如果setp是整数的话,用法将会和range一样,只是一个返回的是python的list类型,一个返回的是array


   # 3. 如果step是非整数的话,返回的结果经常是不稳定的,最好是使用numpy.linspace代替

   #### 参数说明


   # start 可选参数,默认是0,开始的数字


   # stop  必选参数,结束的数字,一般情况下不包括这个数字,如果step是float的类型的话,最后结束的时候,四舍五入可能会超过这个数字


   # step  可选参数,默认是1 间隔的数字,两个数字之差,如果step作为位置参数的话,start也必须给出。


   # dtype 可选参数,返回的是数据的类型,如果没有指定,将会推断给出。


import numpy as np
# 只使用stop这个必要参数
print(np.arange(10))
# 使用前两个参数
print(np.arange(1,8))
# 使用前三个参数
print(np.arange(1,8,3))
# 使用数据类型参数
print(np.arange(1,8,2,"float"))
'''
[0 1 2 3 4 5 6 7 8 9]
[1 2 3 4 5 6 7]
[1 4 7]
[1. 3. 5. 7.]
'''


目录
相关文章
|
8月前
|
数据处理 Python
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
439 0
|
7月前
|
JavaScript API
【Vue2.0源码学习】变化侦测篇-Array的变化侦测
【Vue2.0源码学习】变化侦测篇-Array的变化侦测
22 0
|
9月前
|
C++ 容器
STL容器篇之array与vector(学习篇)(下)
STL容器篇之array与vector(学习篇)(下)
|
9月前
|
C语言 C++ 容器
STL容器篇之array与vector(学习篇)(上)
STL容器篇之array与vector(学习篇)
|
10月前
|
PHP
php函数基础学习:array_chunk() 函数把一个数组分割为新的数组块
php函数基础学习:array_chunk() 函数把一个数组分割为新的数组块
41 0
|
12月前
|
存储 异构计算 Python
解决numpy.core._exceptions.MemoryError: Unable to allocate 1.04 MiB for an array
但实际上它保存的不是模型文件,而是参数文件文件。在模型文件中,存储完整的模型,而在状态文件中,仅存储参数。因此,collections.OrderedDict只是模型的值。
1442 0
|
Web App开发 JavaScript 前端开发
学习Array类型看这一篇就够了(Array类型特点,Array原型方法,浏览器sort底层实现,深浅拷贝)
学习Array类型看这一篇就够了(Array类型特点,Array原型方法,浏览器sort底层实现,深浅拷贝)
105 0
|
Python
numpy重新学习系列-numpy的四则运算(13)
numpy重新学习系列-numpy的四则运算(13)
58 0
|
Python
numpy重新学习系列-如何设置numpy的打印信息输出量(12)
numpy重新学习系列-如何设置numpy的打印信息输出量(12)
69 0
|
Python
numpy重新学习系列(11)---如何用np.linspace生成等间距的N个数字
numpy重新学习系列(11)---如何用np.linspace生成等间距的N个数字
172 0
numpy重新学习系列(11)---如何用np.linspace生成等间距的N个数字