Python数据分析包——NumPy(Numerical Python)

本文介绍了NumPy中ndarray的基本创建方法,包括array(), asarray(), arange()等,并讲解了ones(), zeros(), empty()等实用函数。同时,还探讨了如何通过eye()和identity()创建单位矩阵以及如何使用size, ndim, shape和dtype属性来查看数组信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

整个NumPy最核心的部分就是ndarray,它是“一个具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组”。

1.ndarray创建函数

(1)array(),asarray(),arange()

array可以将输入数据转换为ndarray,输入的数据可以是列表,元组,数组或者其他序列类型,asarray功能和array一样。

arange输入一个N(int类型)值,返回由0~N-1共N个值的数组,类似于python内置的range。


(2)ones(),zeros(),empty()

ones生成一个全1数组,zeros生成一个全0数组,这个函数在进行数据分析的时候比较常用到。

empty生成一个新数组,但是其实是没有值的(不是0,是没有),只分配了内存空间。


(3)eye(),idengtity()

 eye和identity能够创建一个N维的单位矩阵

2.数组属性查看

numpy中size函数可以获得数组中元素的数量,ndim可以返回数组位数,shape返回数组的行列数,dtype返回数组中元素的类型

3.数组索引和切片


Numerical Python by Robert Johansson shows you how to leverage the numerical and mathematical capabilities in Python, its standard library, and the extensive ecosystem of computationally oriented Python libraries, including popular packages such as NumPy, SciPy, SymPy, Matplotlib, Pandas, and more, and how to apply these software tools in computational problem solving. Python has gained widespread popularity as a computing language: It is nowadays employed for computing by practitioners in such diverse fields as for example scientific research, engineering, finance, and data analytics. One reason for the popularity of Python is its high-level and easy-to-work-with syntax, which enables the rapid development and exploratory computing that is required in modern computational work. After reading and using this book, you will have seen examples and case studies from many areas of computing, and gained familiarity with basic computing techniques such as array-based and symbolic computing, all-around practical skills such as visualisation and numerical file I/O, general computat ional methods such as equation solving, optimization, interpolation and integration, and domain-specific computational problems, such as differential equation solving, data analysis, statistical modeling and machine learning. Specific topics that are covered include: How to work with vectors and matrices using NumPy How to work with symbolic computing using SymPy How to plot and visualize data with Matplotlib How to solve linear and nonlinear equations with SymPy and SciPy How to solve solve optimization, interpolation, and integration problems using SciPy How to solve ordinary and partial differential equations with SciPy and FEniCS How to perform data analysis tasks and solve statistical problems with Pandas and SciPy How to work with statistical modeling and machine learning with statsmodels and scikit-learn How to handle file I/O using HDF5 and other common file formats for numerical data How to optimize Python code using Numba and Cython
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值