Skip to Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
2.1 多引數函數映射(Mapping)
|
35
Apply
指令也可接受第三個引數,用來指定
作用層數
(level),此用法可以不用
Map
而
獲得相同的效用。[Page-034]
在此我們將
Plus
指令作用於層數
{1}
,這限制
Apply
指令僅作用於第一層元素。此處使
用了
預留位置序列
##
(slot sequence),用來帶入所有的引數。因為這個用法很常見,
Mathematica 提供一個算符
@@@
直接達到此功能,用於此範例中,可進一步省略
##
而獲
得更簡潔的程式碼。
當你想要於函數中使用其他引數時,還是必須使用
##
,如以下範例:
下式表示於每一項總和中,再加一次第二個元素,即第二個元素被加了兩次。
使用以上的語法,我們可以獲得簡化版的折扣訂單總和。
若串列具較深層的巢狀結構,你可以指定較大的作用層數獲得所需結果。例如前例訂單
被置放於
envelope
額外結構下時:
綜合使用
Map
與
Apply
指令也可獲得相同結果,因為
Ma
p 指令也接受作用層數指定。
ch02.indd 35 2014/4/2 上午 03:31:59
36
|
第二章
當然,你也可以刪除
envelope
的包覆,這可以透過取出指定元素
[[All,2]]
達到,這語
法代表將第一層各元素的第二個元素取出。[Page-035]
以下程式僅使用
Map ...
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

Mathematica Cookbook

Mathematica Cookbook

Sal Mangano
人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar

Publisher Resources

ISBN: 9789863470106