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 錦囊妙計
196
|
第五章
延伸資訊
如 果 你 有 一 字 串 串 列, 並 想 擷 取 匹 配 模 式 的 字 串, 此 時 須 使 用
Select
指 令 搭 配
StringMatchQ
作為模式匹配測試,而不是
StringCases
指令,詳見訣竅 4.1。[Page-196]
5.4 字串複製
問題點
你想串接重複的字串為新字串。
解決方案
使用
StringJoin[]
指令串接字串串列。
ch05.indd 196 2014/4/2 上午 06:13:09
5.4 字串複製
|
197
討論說明
這個解法十分簡單,之所以將此問題納入本書,是因為你也許會覺得 Mathematica 應該
要為本功能提供內建指令,但事實上卻付之闕如。對於大多數應用實例,這個解法沒有
問題,但對於大數量的複製動作,另一個複製方法會更有效率。原理是以重複雙倍的動
作複製字串,直到大於指定數目且最接近 2 的冪次方,再擷取指定數目的字串數量。
n * StringLength[seed]
本方法可能有點難解,讓我們仔細看來。純函數
#<>#&
作用於字串串列會將字串複製
(回憶一下,
<>
算符用來串接字串)。[Page-197]
以下則會將字串複製兩次,也就是原字串的 4 倍。
重複進行此步驟
m
次,可以串接原字串的
2^m
倍,然而所需重複次數不見得
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