Skip to Content
高效能PYTHON程式設計
book

高效能PYTHON程式設計

by Micha Gorelick, Ian Ozsvald
August 2015
Intermediate to advanced
384 pages
7h 42m
Chinese
GoTop Information, Inc.
Content preview from 高效能PYTHON程式設計
116
|
第六章
進入 numpy
為了處理使用
perf
發現的記憶體破碎,我們必須找到能夠有效地將操作向量化的套件,
幸運的是,
numpy
擁有我們需要的一切功能—它將資料儲存在連續的記憶體區塊中,並
且支援資料的向量化操作,因此,我們對
numpy
陣列所做的計算全都以區塊的形式發
生,而不需要特地去繞行每個元素,這樣不僅讓矩陣計算容易很多,並且更加快速。讓
我們看一個範例︰
from array import array
import numpy
def norm_square_list(vector):
"""
>>> vector = range(1000000)
>>> %timeit norm_square_list(vector_list)
1000 loops, best of 3: 1.16 ms per loop
"""
norm = 0
for v in vector:
norm += v*v
return norm
def norm_square_list_comprehension(vector):
"""
>>> vector = range(1000000)
>>> %timeit norm_square_list_comprehension(vector_list)
1000 loops, best of 3: 913 μs per loop
"""
return sum([v*v for v in vector])
def norm_squared_generator_comprehension(vector): ...
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

Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino
手把手教会你linux

手把手教会你linux

桑德.范.乌格特
流畅的Python

流畅的Python

Luciano Ramalho
精通機器學習

精通機器學習

Aurélien Géron

Publisher Resources

ISBN: 9789863477105