python引入数学模块_python导入numpy模块_Python之路-numpy模块

本文详细介绍了Python的NumPy库,包括其安装、使用Jupyter Notebook的配置步骤,以及如何导入和使用NumPy。文章强调了NumPy作为科学计算基础包的角色,特别是其ndarray数据结构,提供了创建、修改和操作多维数组的方法。内容涵盖了NumPy的基本数据类型、属性、数据操作、数组创建、切片、布尔索引、通用函数等功能,并通过实例演示了这些概念的应用。
摘要由CSDN通过智能技术生成

这里是首先需要安装好Anaconda

配置好环境之后开始使用Jupyter Notebook

1.打开cmd,输入 jupyter notebook --generate-config

2.打开这个配置文件,找到“c.NotebookApp.notebook_dir=‘’ ”, 把路径改成自己的工作目录

使用notepad++打开这个文件,大概在124行添加自己的工作目录

c.NotebookApp.notebook_dir = 'D:\Python'    注意:去掉注释符合,前面不能有空格

3.配置文件修改完成后, 以后在jupyter notebook中写的代码等都会保存在自己创建的目录中。

Scipy库简介

Scipy库是基于Python生态的一款开源数值计算、科学与工程应用的开源软件,主要包括NumPy、Scipy、pandas、matplotlib等等。

numPy、Scipy、pandas、matplotlib简介

numpy——基础,以矩阵为基础的数学计算模块,纯数学存储和处理大型矩阵。 这个是很基础的扩展,其余的扩展都是以此为基础。

scipy——数值计算库,在numPy库的基础上增加了众多的数学、科学以及工程计算中常用的库函数。 方便、易于使用、专为科学和工程设计的Python工具包.它包括统计,优化,整合,线性代数模块,傅里叶变换,信号和图像处理,常微分方程求解器等等。

pandas——数据分析,基于numPy 的一种工具,为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具。

matplotlib——绘图,对于图像美化方面比较完善,可以自定义线条的颜色和式样,可以在一张绘图纸上绘制多张小图,也可在一张图上绘制多条线,可以很方便的对数据进行可视化分析。

NumPy历史

1995年Jim HugUNin开发了Numeric

随后Numarray包诞生

Travis Oliphants整合Numeric和Numarray,开发NumPy,2006年第一个版本诞生

使用Anaconda发行版的Python,已经安装好NumPy模块,所以可以不用再安装NumPy模块了。

依照标准的NumPy标准,习惯使用import numpy as np的方式导入该模块。

NumPy模块

numPy:Numerical Python,即数值Python包,是Python进行科学计算的一个基础包,所以是一个掌握其他Scipy库中模块的基础模块,一定需要先掌握该包的主要使用方式。

NumPy模块是Python的一种开源的数值计算扩展,是一个用python实现的科学计算包,主要包括:

一个具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组,称为ndarray(N-dimensional array object)

用于对整组数据进行快速运算的标准数学函数:ufunc(universal function object)

实用的线性代数、傅里叶变换和随机数生成函数。

NumPy和稀疏矩阵的运算包Scipy配合使用更加方便。

NumPy核心数据结构:ndarray

NumPy的数组类被称作ndarray。通常被称作数组。注意numpy.array和标准Python库类array.array并不相同,后者只处理一维数组和提供少量功能。

一种由相同类型的元素组成的多维数组,元素数量是实现给定好的

元素的数据类型由dtype(data-type)对象来指定,每个ndarray只有一种dtype类型

ndarray的大小固定,创建好数组后数组大小是不会再发生改变的

ndarray创建

可以通过numpy模块中的常用的几个函数进行创建ndarray多维数组对象,主要函数如下:

array函数:接收一个普通的python序列,并将其转换为ndarray

zeros函数:创建指定长度或者形状的全零数组。

ones函数:创建指定长度或者形状的全1数组。

empty函数:创建一个没有任何具体值的数组(准备地说是创建一些未初始化的ndarray多维数组)

练习

In [1]:

import numpy as np

创建数组

In [2]:

help(np.array)

Help on built-in function array in module numpy.core.multiarray:

array(...)

array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)

Create an array.

Parameters

----------

object : array_like

An array, any object exposing the array interface, an

object whose __array__ method returns an array, or any

(nested) sequence.

dtype : data-type, optional

The desired data-type for the array. If not given, then

the type will be determined as the minimum type required

to hold the objects in the sequence. This argument can only

be used to 'upcast' the array. For downcasting, use the

.astype(t) method.

copy : bool, optional

If true (default), then the object is copied. Otherwise, a copy

will only be made if __array__ returns a copy, if obj is a

nested sequence, or if a copy is needed to satisfy any of the other

requirements (`dtype`, `order`, etc.).

order : {'C', 'F', 'A'}, optional

Specify the order of the array. If order is 'C', then the array

will be in C-contiguous order (last-index varies the fastest).

If order is 'F', then the returned array will be in

Fortran-contiguous order (first-index varies the fastest).

If order is 'A' (default), then the returned array may be

in any order (either C-, Fortran-contiguous, or even discontiguous),

unless a copy is required, in which case it will be C-contiguous.

subok : bool, optional

If True, then sub-classes will be passed-through, otherwise

the returned array will be forced to be a base-class array (default).

ndmin : int, optional

Specifies the minimum number of dimensions that the resulting

array should have. Ones will be pre-pended to the shape as

needed to meet this requirement.

Returns

-------

out : ndarray

An array object satisfying the specified requirements.

See Also

--------

empty, empty_like, zeros, zeros_like, ones, ones_like, fill

Examples

--------

>>> np.array([1, 2, 3])

array([1, 2, 3])

Upcasting:

>>> np.array([1, 2, 3.0])

array([ 1., 2., 3.])

More than one dimension:

>>> np.array([[1, 2], [3, 4]])

array([[1, 2],

[3, 4]])

Minimum dimensions 2:

>>> np.array([1, 2, 3], ndmin=2)

array([[1, 2, 3]]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值