Skip to Content
優雅的SciPy|Python科學研究的美學
book

優雅的SciPy|Python科學研究的美學

by Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
May 2018
Intermediate to advanced
276 pages
5h 53m
Chinese
GoTop Information, Inc.
Content preview from 優雅的SciPy|Python科學研究的美學
使用稀疏座標矩陣的列聯表 |
125
不幸地,即使 COO 格式很直觀,它還是無法最小化記憶體的使用,也無法在計算時將
穿越陣列的次數儘可能的減少。(還記得在第一章時看過,
data locality
對於計算效率的
影響吧)不過,當你看著你寫出的 COO 的結果,還是能幫助識別出冗餘資訊,例如那
些重複的 1。(譯註:指練習題解答)
壓縮稀疏列格式
如果我們使用 COO 時,用一列列的順序例出非 0 的項目,而不是任意跳來跳去的話
(這種格式也支援),最後我們的 row 陣列就會有很多連續又重複的值(譯按:如同
練習題裡第 1 row 4 個連續的 1)。我們可以將這些連續重複的值在下列開始時壓縮
col
索引
之中,而不是一直重複的寫列索引,這就是
壓縮稀疏列
compressed sparse
row
CSR
)格式的基本精神。
再一次用上面的範例舉例,如果是 CSR 格式,
col
data
陣列不會變(但
col
會改名為
indices
)。然後,
row
陣列改為用來指出
col
何處
為列的開頭處,並將 row 陣列改名
indptr
,意思是索引指標(index pointer)。
那麼,讓我們看一下 COO 格式中的
row
col
陣列,先不管
data
陣列:
row = [0, 1, 1, 1, 1, 2, 3, 4, 4]
col = [2, 0, 1, 3, 4, 1, 0, 3, 4]
每次
row
中的值改變時,就是一個列的開頭,第 0 列從索 0 引開始,而第 1 列由索引 1
開始,但是第 2 列,是在
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

JAVASCRIPT網頁應用程式設計

JAVASCRIPT網頁應用程式設計

Alex MacCaw
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
初探深度學習|使用TensorFlow

初探深度學習|使用TensorFlow

Reza Zadeh, Bharath Ramsundar
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉

Publisher Resources

ISBN: 9789864767878