SlideShare una empresa de Scribd logo
1 de 7
多次元配列機能比較
田中昌宏 2016-02-20
Numpy多次元配列の機能
1. Slice View
• 配列のスライスは、元の配列のビューになる。
2. Broadcasting
• 要素数が1の次元のとき、要素を繰り返して適用。
3. Index/Mask array
• 配列のスライスに与えるインデックスが、
• bool配列のとき、Trueの位置の要素を参照
• int配列のとき、インデックスとして参照
1. Slice View
• a[2:4] のようなスライスは、元の配列のビューになる。
>>> a = numpy.arange(5)
array([0, 1, 2, 3, 4])
>>> b = a[2:4]
array([2, 3])
>>> b[:] = 9
array([9, 9])
>>> a
array([0, 1, 9, 9, 4])
• もともと要素参照が a[k][j][i] という記法だったためと思われる。
• Viewによってコピー不要になる例:
• a[3:7] += 5
• diff = a[1:-2] - a[0:-1]
• NArray旧版では不採用
2. Broadcasting
• 配列の演算で、一方の配列のある次元の要素数が1のとき、要
素が繰り返して適用される。
• numpy.arange(4).reshape(4,1) * numpy.arange(5).reshape(1,5)
• Broadcasting がなければ、演算の前に n*m の配列を作らなけれ
ばならない。
• 配列とスカラーの演算も、Broadcastingの一種とみなせる。
0
1
2
3
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
0 3 6 9 12
* 0 1 2 3 4 =
3. Index/Mask array
>>> a = numpy.array([1,-2,3,-4,-5])
array([ 1, -2, 3, -4, -5])
>>> bool = a<0
array([False, True, False, True, True], dtype=bool)
>>> a[bool]
array([-2, -4, -5])
>>> index = numpy.where(bool)
(array([1, 3, 4]),)
>>> a[index]
array([-2, -4, -5])
>>> a[a<0] = 0
>>> a
array([1, 0, 3, 0, 0])
(初期のNumpyにはなかった機能)
機能比較
Numpy NMatrix 旧NArray 新NArray
Slice View ○ ○ × ○
Broadcasting ○ ×(dotのみ) ○ ○
Index/Mask ○ × ○ ○
1.0 * a ○ × ○ ○
雑感
• NMatrixは、多次元配列としては機能不足。しかし、
疎行列機能がある点は優位。
• NArray旧版は、ありがたいことにいろいろなところ
で使われているが、捨てて新しい方に移りたい…
• NArray新版は、
• 基本的な部分はほぼできている。
• モジュール名をつけたいが、名前が決まらない…
• 細かい実装で気になる部分は多数。
• 整理・リファクタリングも必要。

Más contenido relacionado

La actualidad más candente

Cf219 d1d
Cf219 d1dCf219 d1d
Cf219 d1d
DEGwer
 
Vinculum
VinculumVinculum
Vinculum
tomerun
 

La actualidad más candente (12)

Hash mapとは
Hash mapとはHash mapとは
Hash mapとは
 
アルゴリズムとデータ構造10
アルゴリズムとデータ構造10アルゴリズムとデータ構造10
アルゴリズムとデータ構造10
 
すうがく初めの一歩
すうがく初めの一歩すうがく初めの一歩
すうがく初めの一歩
 
アルゴリズムとデータ構造9
アルゴリズムとデータ構造9アルゴリズムとデータ構造9
アルゴリズムとデータ構造9
 
programming camp 2008, introduction of programming, algorithm
programming camp 2008, introduction of programming, algorithmprogramming camp 2008, introduction of programming, algorithm
programming camp 2008, introduction of programming, algorithm
 
[アルゴリズムイントロダクション勉強会] ハッシュ
[アルゴリズムイントロダクション勉強会] ハッシュ[アルゴリズムイントロダクション勉強会] ハッシュ
[アルゴリズムイントロダクション勉強会] ハッシュ
 
200319 eash python_shareslide_functions
200319 eash python_shareslide_functions200319 eash python_shareslide_functions
200319 eash python_shareslide_functions
 
何が選ばれたかという情報から評価関数推定2
何が選ばれたかという情報から評価関数推定2何が選ばれたかという情報から評価関数推定2
何が選ばれたかという情報から評価関数推定2
 
Cf219 d1d
Cf219 d1dCf219 d1d
Cf219 d1d
 
固有値の問題
固有値の問題固有値の問題
固有値の問題
 
固有値問題
固有値問題固有値問題
固有値問題
 
Vinculum
VinculumVinculum
Vinculum
 

Destacado

Ruby科学データ処理ツールの開発 NArrayとPwrake
Ruby科学データ処理ツールの開発 NArrayとPwrakeRuby科学データ処理ツールの開発 NArrayとPwrake
Ruby科学データ処理ツールの開発 NArrayとPwrake
Masahiro Tanaka
 
Rubyと機械学習の現状
Rubyと機械学習の現状Rubyと機械学習の現状
Rubyと機械学習の現状
Aki Ariga
 
Weekly news 4
Weekly news 4Weekly news 4
Weekly news 4
ASekhon
 
メモリアロケーションからみた拡張ライブラリに大切なこと
メモリアロケーションからみた拡張ライブラリに大切なことメモリアロケーションからみた拡張ライブラリに大切なこと
メモリアロケーションからみた拡張ライブラリに大切なこと
Masaya TARUI
 
Newscurve StartupStandup pitch deck
Newscurve StartupStandup pitch deckNewscurve StartupStandup pitch deck
Newscurve StartupStandup pitch deck
boccio
 
SO - Correo
SO - CorreoSO - Correo
SO - Correo
maricel
 
Inauguracion kubik programa
Inauguracion kubik programaInauguracion kubik programa
Inauguracion kubik programa
kubikbytecnalia
 
2012 Volkswagen Beetle review from edmunds
2012 Volkswagen Beetle review from edmunds2012 Volkswagen Beetle review from edmunds
2012 Volkswagen Beetle review from edmunds
Courtney Boone
 

Destacado (20)

Ruby科学データ処理ツールの開発 NArrayとPwrake
Ruby科学データ処理ツールの開発 NArrayとPwrakeRuby科学データ処理ツールの開発 NArrayとPwrake
Ruby科学データ処理ツールの開発 NArrayとPwrake
 
Rubyと機械学習の現状
Rubyと機械学習の現状Rubyと機械学習の現状
Rubyと機械学習の現状
 
Weekly news 4
Weekly news 4Weekly news 4
Weekly news 4
 
CROSS 2015 モバイル開発環境セッション
CROSS 2015 モバイル開発環境セッションCROSS 2015 モバイル開発環境セッション
CROSS 2015 モバイル開発環境セッション
 
メモリアロケーションからみた拡張ライブラリに大切なこと
メモリアロケーションからみた拡張ライブラリに大切なことメモリアロケーションからみた拡張ライブラリに大切なこと
メモリアロケーションからみた拡張ライブラリに大切なこと
 
2011 Volkswagen Routan For Sale at Keffer Volkswagen, Charlotte NC
2011 Volkswagen Routan For Sale at Keffer Volkswagen, Charlotte NC2011 Volkswagen Routan For Sale at Keffer Volkswagen, Charlotte NC
2011 Volkswagen Routan For Sale at Keffer Volkswagen, Charlotte NC
 
Newscurve StartupStandup pitch deck
Newscurve StartupStandup pitch deckNewscurve StartupStandup pitch deck
Newscurve StartupStandup pitch deck
 
2011 Outlander For Sale at Keffer Mitsubishi, Charlotte North Carolina
2011 Outlander For Sale at Keffer Mitsubishi, Charlotte North Carolina2011 Outlander For Sale at Keffer Mitsubishi, Charlotte North Carolina
2011 Outlander For Sale at Keffer Mitsubishi, Charlotte North Carolina
 
Pwrake: Distributed Workflow Engine for e-Science - RubyConfX
Pwrake: Distributed Workflow Engine for e-Science - RubyConfXPwrake: Distributed Workflow Engine for e-Science - RubyConfX
Pwrake: Distributed Workflow Engine for e-Science - RubyConfX
 
Muscle and neural tissues
Muscle and neural tissuesMuscle and neural tissues
Muscle and neural tissues
 
Etikalab research to website
Etikalab research to websiteEtikalab research to website
Etikalab research to website
 
SO - Correo
SO - CorreoSO - Correo
SO - Correo
 
990617speech(chou)
990617speech(chou)990617speech(chou)
990617speech(chou)
 
Inauguracion kubik programa
Inauguracion kubik programaInauguracion kubik programa
Inauguracion kubik programa
 
Cool Pro & Amp;Biz oktober 2015
Cool Pro & Amp;Biz oktober 2015Cool Pro & Amp;Biz oktober 2015
Cool Pro & Amp;Biz oktober 2015
 
AIChE 2011 - Automatic Reaction Mechanism Generation with Group Additive Kine...
AIChE 2011 - Automatic Reaction Mechanism Generation with Group Additive Kine...AIChE 2011 - Automatic Reaction Mechanism Generation with Group Additive Kine...
AIChE 2011 - Automatic Reaction Mechanism Generation with Group Additive Kine...
 
2012 Volkswagen Beetle review from edmunds
2012 Volkswagen Beetle review from edmunds2012 Volkswagen Beetle review from edmunds
2012 Volkswagen Beetle review from edmunds
 
Intro terminology
Intro terminologyIntro terminology
Intro terminology
 
Next Generation Workflows - SharePoint Day 2013
Next Generation Workflows - SharePoint Day 2013Next Generation Workflows - SharePoint Day 2013
Next Generation Workflows - SharePoint Day 2013
 
Tissues epithelial
Tissues epithelialTissues epithelial
Tissues epithelial
 

多次元配列機能比較