Skip to Main Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate content levelBeginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
3.1 確認數值串列的執行效率
|
95
3.1 確認數值串列的執行效率
問題點
你正針對大型向量、矩陣或高階張量進行大量的數學運算,你想了解如何以最具空間與
速度效率的方式包裝這些資料。
解決方案
請確認你的串列是
緊實陣列
packed arrays
而非多種數值型態的混合體。緊實陣列的
意思是所有陣列元都是同種型態,全為整數或全為浮點數,但單一型態的矩陣元是緊實
陣列的必要條件而非充分條件。輸出大型串列數值時,Mathematica 會試著盡量輸出緊
實陣列,但有些程式細節卻會妨礙緊實陣列的輸出。
以下是兩個相當類似的程式範例,但卻只有第二個範例的輸出才是緊實陣列。
兩程式之差異在於,第一個程式先以
Table
指令輸出符號形式,接著才使用
N
指令轉為
實數,因此雖然最後的結果符合緊實陣列條件,但
N
指令卻不會將其轉為緊實陣列;而
第二個程式中,藉由指定
i
立即為實數強迫
Table
指令建立實數串列,因此不須再使用
N
指令,且
Table
指令會自動輸出緊實陣列。[ Page-96]
討論說明
為了深入了解緊實陣列的好處,我們可以讓 Mathematica 輸出陣列所需之記憶體空間。
ch03.indd 95 2014/4/2 下午 05:37:05
96
|
第三章
馬上可以看出,緊實陣列節省了可觀的記憶體,實際上,緊實陣
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.
Start your free trial

You might also like

Ubuntu for Non-Geeks, 4th Edition

Ubuntu for Non-Geeks, 4th Edition

Rickford Grant, Phil Bull

Publisher Resources

ISBN: 9789863470106