学习笔记之NumPy

本文介绍了NumPy的基本概念,包括数组创建、索引、切片等操作,以及高级功能如广播法则和线性代数计算。同时提供了实用的例子,如使用NumPy计算两点之间的距离、角度和条件语句的应用。

NumPy — NumPy

  • http://www.numpy.org/
  • NumPy is the fundamental package for scientific computing with Python.

NumPy - Wikipedia

NumPy - 维基百科,自由的百科全书

  • https://zh.wikipedia.org/wiki/NumPy
  • NumPyPython语言的一个扩充程序库。支持高阶大量的维度数组矩阵运算,此外也针对数组运算提供大量的数学函数。NumPy的前身Numeric最早是由Jim Hugunin与其它协作者共同开发,2005年,Travis Oliphant在Numeric中结合了另一个同性质的程序库Numarray的特色,并加入了其它扩展而开发了NumPy。NumPy为开放源代码并且由许多协作者共同维护开发。

Numpy详细教程 - 机器学习算法与Python学习

  • https://mp.weixin.qq.com/s/MtwGkIhHvcaU-vmC89FfGA
  • NumPy 是一个 Python 包。 它代表 “Numeric Python”。 它是一个由多维数组对象和用于处理数组的例程集合组成的库。
  • Numeric,即 NumPy 的前身,是由 Jim Hugunin 开发的。 也开发了另一个包 Numarray ,它拥有一些额外的功能。 2005年,Travis Oliphant 通过将 Numarray 的功能集成到 Numeric 包中来创建 NumPy 包。 这个开源项目有很多贡献者。
  • Numpy基础
    • 创建数组
    • 打印数组
    • 基本运算
    • 通用函数(ufunc)
    • 索引,切片和迭代
    • 形状操作
    • 组合(stack)不同的数组
    • 将一个数组分割(split)成几个小数组
    • 视图(view)和浅复制
    • 深复制
    • 函数和方法(method)总览
  • 进阶
    • 广播法则(rule)
    • 花哨的索引和索引技巧
    • 通过数组索引
    • 通过布尔数组索引
    • ix_()函数
    • 线性代数
    • 矩阵类
    • 索引:比较矩阵和二维数组
  • 技巧和提示
    • 向量组合(stacking)
    • 直方图(histogram)

【Data Mining】机器学习三剑客之Numpy常用用法总结

盘一盘 Python 系列 2 - NumPy 


How to calculate distance between two points ?

  • python - How can the euclidean distance be calculated with numpy? - Stack Overflow
    • https://stackoverflow.com/questions/1401712/how-can-the-euclidean-distance-be-calculated-with-numpy
    • dist = numpy.linalg.norm(a-b)
  • numpy.linalg.norm — NumPy v1.9 Manual
    • https://docs.scipy.org/doc/numpy-1.9.3/reference/generated/numpy.linalg.norm.html

How to calculate angle from velocity ?

  • 2d - Calculating the angular direction from velocity - Game Development Stack Exchange
    • https://gamedev.stackexchange.com/questions/17340/calculating-the-angular-direction-from-velocity
    • angle = atan2 (vy,vx)
  • Radian - Wikipedia
    • https://en.wikipedia.org/wiki/Radian
    • The radian (SI symbol rad) is the SI unit for measuring angles, and is the standard unit of angular measure used in many areas of mathematics. The length of an arc of a unit circle is numerically equal to the measurement in radians of the angle that it subtends; one radian is just under 57.3 degrees (expansion at OEISA072097). The unit was formerly an SI supplementary unit, but this category was abolished in 1995 and the radian is now considered an SI derived unit.
  • numpy.arctan2 — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy/reference/generated/numpy.arctan2.html#numpy.arctan2
    • Element-wise arc tangent of x1/x2 choosing the quadrant correctly.
    • The quadrant (i.e., branch) is chosen so that arctan2(x1, x2) is the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (x2x1). (Note the role reversal: the “y-coordinate” is the first function parameter, the “x-coordinate” is the second.) By IEEE convention, this function is defined for x2 = +/-0 and for either or both of x1 and x2 = +/-inf (see Notes for specific values).
    • This function is not defined for complex-valued arguments; for the so-called argument of complex values, use angle.
    • angle = np.arctan2(vy, vx) * 180 / np.pi

How to use conditional statement on array ?

  • (Python) How to use conditional statements on every element of array using [:] syntax? - Stack Overflow
    • https://stackoverflow.com/questions/45848612/python-how-to-use-conditional-statements-on-every-element-of-array-using-s
    • all(i == 0 for i in a)
    • a[a > 1] = 1
    • map(lambda x: 1 if x==0 else x, a)
    • a = np.where(a == 0, 1, a)
  • python - Function of Numpy Array with if-statement - Stack Overflow
    • https://stackoverflow.com/questions/8036878/function-of-numpy-array-with-if-statement
    • vfunc = vectorize(func)
  • numpy.array — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html?highlight=array#numpy.array
    • numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)
  • numpy.where — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html?highlight=numpy%20where#numpy.where
    • Return elements, either from x or y, depending on condition.
    • If only condition is given, return condition.nonzero().
  • numpy.vectorize — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html
    • class numpy.vectorize(pyfunc, otypes=None, doc=None, excluded=None, cache=False, signature=None)
    • Define a vectorized function which takes a nested sequence of objects or numpy arrays as inputs and returns an single or tuple of numpy array as output. The vectorized function evaluates pyfunc over successive tuples of the input arrays like the python map function, except it uses the broadcasting rules of numpy.
    • The data type of the output of vectorized is determined by calling the function with the first element of the input. This can be avoided by specifying the otypes argument.

How to convert array into string ?

  • numpy.array_str — NumPy v1.9 Manual
  • http://memobio2015.u-strasbg.fr/conference/FICHIERS/Documentation/doc-numpy-html/reference/generated/numpy.array_str.html

How to compare ?

  • numpy.maximum — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.maximum.html
    • numpy.maximum(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'maximum'>
  • numpy.minimum — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.minimum.html
    • numpy.minimum(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'minimum'>
  • numpy.nanmax — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.nanmax.html
    • numpy.nanmax(a, axis=None, out=None, keepdims=<no value>)
  • numpy.nanmin — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.nanmin.html
    • numpy.nanmin(a, axis=None, out=None, keepdims=<no value>)
  • Constants — NumPy v1.15 Manual
    • https://docs.scipy.org/doc/numpy-1.15.1/reference/constants.html?highlight=numpy%20nan#numpy.inf
      • numpy.inf
    • https://docs.scipy.org/doc/numpy-1.15.1/reference/constants.html?highlight=numpy%20nan#numpy.nan
      • numpy.nan

转载于:https://www.cnblogs.com/pegasus923/p/9022893.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值