python numpy_用于基本功能的numpy速查表python

python numpy 终极指南 (ULTIMATE GUIDE)Numpy (which stands for Numerical Python) is a library available in Python programming language, supporting matrix data structures and multidimensional array objects...
摘要由CSDN通过智能技术生成

python numpy

终极指南 (ULTIMATE GUIDE)

Numpy (which stands for Numerical Python) is a library available in Python programming language, supporting matrix data structures and multidimensional array objects. This the most basic scientific computing library that we need to learn, to begin our journey in the field of data science.

Numpy( 代表 Numeric Python )是一个可用Python编程语言提供的库,支持矩阵数据结构和多维数组对象。 这是我们需要学习的最基本的科学计算库,以开始我们在数据科学领域的旅程。

Numpy can compute basic mathematical calculations to make the process of creating advanced machine learning and artificial intelligence applications easier (by using comprehensive mathematical functions available within the library). Numpy allows us to carry out various complex mathematical calculations effortlessly along with several top-up libraries (like matplotlib, pandas, scikit-learn, etc.) built over it.

Numpy可以计算基本的数学计算 ,从而简化创建高级机器学习和人工智能应用程序的过程(通过使用库中提供的全面数学函数)。 Numpy允许我们轻松地进行各种复杂的数学计算,以及在其上构建的数个充值库(例如matplotlib,pandas,scikit-learn等)。

This library is a great tool for every data science professional to handle and analyze the data efficiently. Moreover, it is much easier to perform mathematical operations with numpy arrays in comparison to python’s list.

该库是每位数据科学专业人员有效处理和分析数据的好工具。 而且,与python的列表相比,使用numpy数组执行数学运算要容易得多。

Numpy library has various functions available in it. In this article, we will learn some essential and lesser-known functions of this library and how to implement them efficiently.

Numpy库具有各种可用功能。 在本文中,我们将学习该库的一些基本 功能鲜为人知的功能,以及如何有效地实现它们。

Note: In this article, we will be using Google Colaboratory to execute our codes.

注意:在本文中,我们将使用 Google Colaboratory 执行代码。

导入numpy (Importing numpy)

Numpy can be simply imported in the notebook by using the following code:

可以使用以下代码将Numpy轻松导入笔记本中:

import numpy as np

Here, numpy is written as np to save time while coding, and also it is a de facto in the data science community.

在这里,numpy被编写为np以节省编码时的时间,并且它在数据科学界实际上是事实。

Now, let’s get started with numpy functions!

现在,让我们开始使用numpy函数!

使用numpy创建n维数组 (Creation of n-dimensional array using numpy)

An array is a data structure in the numpy library, which is just like a list which can store values, but the differences are that we can specify the data type of elements of an array ( dtype function) and arrays are faster and take less memory to store data, allowing the code to be optimized even further.

数组是numpy库中的数据结构,就像可以存储值的列表一样,但是区别在于我们可以指定数组元素的数据类型( dtype函数),并且数组速度更快,占用的内存更少存储数据,从而可以进一步优化代码。

To create a single-dimensional array we can use the following code:

要创建一维数组,我们可以使用以下代码:

import numpy as np
array = np.array([1,2,3,4,5])

The process for creating a multi-dimensional array is similar, we just have to add more values in []brackets:

创建多维数组的过程 相似,我们只需要在[]括号中添加更多值:

array = np.array([[1.1,2.2,3.0,4.6,5.0],[6.4,7.3,8.5,9.1,10.2])

numpy.linsapce()函数 (numpy.linsapce() function)

This numpy.linspace() function is used to create an array of evenly spaced numbers in a given interval. We can also determine the number of samples we want to generate (however, it is an optional parameter default value is set to fifty samples). Another optional parameter we can add to this function is restep which if True will return the space i.e. spacing between the samples along with the list. The function is: numpy.linspace(start, stop). Let’s apply this function in an example:

numpy.linspace()函数用于在给定间隔中创建均匀间隔的数字数组。 我们还可以确定要生成的样本数(但是,这是一个可选参数,默认值设置为五十个样本)。 我们可以添加到此函数的另一个可选参数是restep ,如果为True则将返回space即样本与列表之间的间隔。 该函数是: numpy.linspace(start, stop) 。 让我们在示例中应用此功能:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,10,10,dtype = int, retstep=True)
pr
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值