numpy.tile and numpy.newaxis for matlab repmat behavior
This is a test to use "Google translate" for a blog entry.
(Google translate)
これにより、ブログエントリのために"Googleは翻訳"を使用するテストです。
I searched twice for this already. Time to take notes.
When I want to do something like below with repmat command in MATLAB:
(Google translate)
私はすでにこのために二度検索。メモを取るための時間。
私はMATLABでrepmatのコマンドを使用してのような下に何かをしたいときは:
a = round(rand(4,5)*10)
4 6 5 2 3
9 6 2 2 9
9 2 8 2 4
6 3 2 4 2
b = repmat(a,[1,1,2])
b(:,:,1) =
4 6 5 2 3
9 6 2 2 9
9 2 8 2 4
6 3 2 4 2
b(:,:,2) =
4 6 5 2 3
9 6 2 2 9
9 2 8 2 4
6 3 2 4 2
To get the equivalent result in Python, use newaxis as follows:
(Google translate)
Pythonで同等の結果を取得するには、次のようにnewaxisを使用してください
import numpy as np
a = np.random.randint(0,10,(4,5))
array([[2, 1, 4, 2, 0],
[5, 1, 8, 7, 8],
[9, 3, 5, 1, 4],
[8, 8, 6, 3, 5]])
b = np.tile(a[:,:,np.newaxis], (1,1,2))
b[:,:,1]
array([[2, 1, 4, 2, 0],
[5, 1, 8, 7, 8],
[9, 3, 5, 1, 4],
[8, 8, 6, 3, 5]])
b[:,:,0]
array([[2, 1, 4, 2, 0],
[5, 1, 8, 7, 8],
[9, 3, 5, 1, 4],
[8, 8, 6, 3, 5]])
Wow! Not bad. With Google translate, i can blog without Japanese IME.
WOW!悪くない。Google翻訳で、私は日本語IMEなしでブログができます。
« 英語版のXPでMeiryo(メイリオ)でブラウジング Firefox 5.0 | トップページ | list slicing in python: get till the last item »
「Python」カテゴリの記事
- Noteの記事をPythonでバックアップしといた。(2021.05.05)
- JupyterLabでも好きな外部エディターを使いたい!(2018.05.02)
- ローカルエリア内のJupyterLabサーバーにLAN経由で接続する。(2018.05.02)
- Juliaやってみよう。五日目。Pythonと速度比較。(2017.08.01)
- Juliaやってみよう。四日目。@timeでプロファイリング(2017.07.16)
「見栄」カテゴリの記事
- デイビッド・ビーズリーのユニットテストで魚が死んだ話。(2016.01.03)
- noteflightでブラウザ上でちょちょいと作曲してみる。(2015.11.30)
- ブルーサムライとサムライブルーの違い(2015.01.16)
- XPS 13 ridiculous noise from CPU cooling fan fixed(2015.01.04)
- エボラから生き延びた3歳児が看護婦さんにプロポーズ(2014.10.18)
「英語」カテゴリの記事
- brasserie(ブラッスリー)とbrassiere(ブラジャー)(2016.09.25)
- デイビッド・ビーズリーのユニットテストで魚が死んだ話。(2016.01.03)
- WindowsでLANネットワーク上にリモートGitレポを作成。(2015.10.17)
- 村上春樹はなぜノーベル賞候補なのか。(2015.10.09)
- Windows -> systemd -> MongoDB -> Sharepoint -> ActiveX(2015.07.30)
« 英語版のXPでMeiryo(メイリオ)でブラウジング Firefox 5.0 | トップページ | list slicing in python: get till the last item »



コメント