Skip to Content
利用 Python 进行数据分析:原书第 3 版
book

利用 Python 进行数据分析:原书第 3 版

by Wes McKinney
November 2023
Intermediate to advanced
512 pages
11h 53m
Chinese
China Machine Press
Content preview from 利用 Python 进行数据分析:原书第 3 版
高阶
NumPy
|
457
但是,如果想用一维的数值数组来设置目标数组的列,只要保证形状兼容就可以了:
A.4
高阶
ufunc
应用
虽然许多
NumPy
用户只会用到通用函数所提供的快速元素级运算,但通用函数实际上
还有一些高级用法能使我们无须循环就能编写更简洁的代码。
A.4.1 ufunc
实例方法
NumPy
的各个二元
ufunc
都有一些用于执行特定向量化运算的特殊方法。表
A-2
汇总了
这些方法,下面我将通过几个具体的例子对它们进行说明。
reduce 接收一个数组,并通过一系列二元运算对其值进行聚合(可指明轴向)。例如,
我们可以用 np.add.reduce 对数组中各个元素进行求和:
458
|
附录
A
起始值取决于
ufunc
(例如,对于 add,就是
0
)。如果传入了轴,约简运算就会沿该轴
向执行。这就使你能用一种比较简洁的方式解决某些问题。在下面这个不太常见的例子
中,我们用 np.logical_and 检查数组各行中的值是不是有序的:
# 为了可以复现
# 对行排序
注意,logical_and.reduce all 方法是等价的。
ufunc
accumulate 方法与 reduce 有关,类似于 cumsum sum 的关系。它生成一个与
中间“累计”值大小相同的数组:
outer 用于计算两个数组之间成对的交叉乘积: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Effective Python 第3版 ―Pythonプログラムを改良する125項目

Effective Python 第3版 ―Pythonプログラムを改良する125項目

Brett Slatkin, 鈴木 駿

Publisher Resources

ISBN: 9787111726722