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.]
'''


目录
相关文章
|
数据采集 机器学习/深度学习 数据可视化
深入学习NumPy库在数据分析中的应用场景
深入学习NumPy库在数据分析中的应用场景
|
索引 Python
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
数据科学:Numpy、Pandas、Matplotlib学习(更新ing...)
190 0
|
数据处理 Python
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
AttributeError: module ‘numpy‘ has no attribute ‘array‘解决办法
1405 0
|
存储 算法 数据挖掘
NumPy 数组学习手册:6~7
NumPy 数组学习手册:6~7
123 0
|
2月前
|
存储 Java 数据处理
(numpy)Python做数据处理必备框架!(一):认识numpy;从概念层面开始学习ndarray数组:形状、数组转置、数值范围、矩阵...
Numpy是什么? numpy是Python中科学计算的基础包。 它是一个Python库,提供多维数组对象、各种派生对象(例如掩码数组和矩阵)以及用于对数组进行快速操作的各种方法,包括数学、逻辑、形状操作、排序、选择、I/0 、离散傅里叶变换、基本线性代数、基本统计运算、随机模拟等等。 Numpy能做什么? numpy的部分功能如下: ndarray,一个具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组 用于对整组数据进行快速运算的标准数学函数(无需编写循环)。 用于读写磁盘数据的工具以及用于操作内存映射文件的工具。 线性代数、随机数生成以及傅里叶变换功能。 用于集成由C、C++
318 1
|
数据可视化 Linux Python
NumPy 随机数据分布与 Seaborn 可视化详解
数据分布是指数据集中所有可能值出现的频率,并用概率来表示。它描述了数据取值的可能性。 Seaborn 是一个基于 Matplotlib 的 Python 数据可视化库,用于创建统计图表。它提供了一系列高级绘图函数,可以轻松创建美观且信息丰富的统计图形。
|
Python
Numpy学习笔记(一):array()、range()、arange()用法
这篇文章是关于NumPy库中array()、range()和arange()函数的用法和区别的介绍。
869 6
Numpy学习笔记(一):array()、range()、arange()用法
|
存储 索引 Python
python学习——NumPy数值计算基础
NumPy基础知识概览:涉及nan(非数字)和inf(无穷)的概念,nan在文件读取或不适当计算时出现,inf在除0操作中出现。数组操作有深拷贝(a=b.copy())、浅拷贝(a=b[:])和引用(a=b)。创建数组方式多样,如`np.array()`、`np.arange()`等。数据类型转换如`np.float64()`、`np.int8()`。随机数生成包含均匀分布、正态分布等。数组索引和切片支持多维操作。改变数组形状用`reshape()`,展平用`ravel()`和`flatten()`。矩阵运算包括加减乘、转置、逆矩阵等。
214 2
python学习——NumPy数值计算基础
|
数据可视化 Linux Python
NumPy 随机数据分布与 Seaborn 可视化详解
本文介绍了数据分布的概念,它是统计学和数据科学的基础,描述了数据可能出现的频率。NumPy的`random`模块支持生成不同分布的随机数,如`choice`用于离散分布,`randn`和`rand`等用于连续分布。此外,还介绍了数组的随机洗牌和排列。通过Seaborn库,可以创建统计图表,如`distplot()`函数用于绘制数据分布图,包括正态分布和自定义分布。最后,文章提供了相关练习及解决方案。
422 0
|
机器学习/深度学习 数据处理 计算机视觉
python Numpy实践学习
python Numpy实践学习
125 1

热门文章

最新文章

  • 1
    PHP 数组查找:为什么 `isset()` 比 `in_array()` 快得多?
    153
  • 2
    Java 中数组Array和列表List的转换
    610
  • 3
    JavaScript中通过array.map()实现数据转换、创建派生数组、异步数据流处理、复杂API请求、DOM操作、搜索和过滤等,array.map()的使用详解(附实际应用代码)
    563
  • 4
    通过array.reduce()实现数据汇总、条件筛选和映射、对象属性的扁平化、转换数据格式、聚合统计、处理树结构数据和性能优化,reduce()的使用详解(附实际应用代码)
    1330
  • 5
    通过array.some()实现权限检查、表单验证、库存管理、内容审查和数据处理;js数组元素检查的方法,some()的使用详解,array.some与array.every的区别(附实际应用代码)
    405
  • 6
    通过array.every()实现数据验证、权限检查和一致性检查;js数组元素检查的方法,every()的使用详解,array.some与array.every的区别(附实际应用代码)
    251
  • 7
    多维数组操作,不要再用遍历循环foreach了!来试试数组展平的小妙招!array.flat()用法与array.flatMap() 用法及二者差异详解
    162
  • 8
    别再用双层遍历循环来做新旧数组对比,寻找新增元素了!使用array.includes和Set来提升代码可读性
    191
  • 9
    Array.forEach实战详解:简化循环与增强代码可读性;Array.forEach怎么用;面对大量数据时怎么提高Array.forEach的性能
    127
  • 10
    深入理解 JavaScript 中的 Array.find() 方法:原理、性能优势与实用案例详解
    464