macでmatplotlibによる画像出力
mac上でskimageを入れた際にエラーになったのでメモ
pyenvにてinstallしたpython3.5にて、pipで入れたskimageによって画像を出力しようとした際エラーになった
発生したエラーはこちら
>from skimage import io >image = io.imread('example.png') >io.imshow(image) RuntimeError: No suitable plugin registered for imshow
描画に必要なライブラリを入れる必要があるのかと考え、matplotlibでグラフを表示できるか試してみるとこれもエラー
>>> import matplotlib.pyplot as plt RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please eith er reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ
ググッてみるとこんなのを見つけた http://qiita.com/katryo/items/918667f28301fdec89ba
今回のケースと同じようなのでこれに従ってbackendを別のものを使うよう変更してみる
$ cat 'backend : TkAgg' >> ~/.matplotlib/matplotlibrc $ python -c 'import matplotlib.pyplot as pyplot; pyplot.pie([1,2,3]); pyplot.show()'
これで無事グラフが表示された
もともとやりたかったexample.pngの出力もうまくいくようになった
vimでnon-greedyなマッチ
vimでnon-greedyなマッチを行うために正規表現を調べたのでメモ
non-greedyなマッチを使いたい場合のusecase
以下の行でクォーテーション毎にそれぞれマッチしたい場合
'hoge', 'fuga'
アスタリスクを使って書くと行頭から行末まで全体にマッチしてしまう
# greedy /\v'.*' => match "'hoge', 'fuga'" # non-greedy /\v'.{-}' => match "'hoge'" and "'fuga'" separately
{}
は繰り返し回数を指定する場合の正規表現の書き方だが、その頭にハイフンを付けることでnon-greedyという意味になる
例えば{-2,5}
とすれば2~5回の繰り返し(non-greedy)を表せる
ちなみに\v
を置くことでalphabet, number, underscore以外の文字を特殊な意味で使う場合にescapeする必要がなくなる
\Vとすれば逆にすべての文字をescapeなしで文字通りのまま扱える
cf. :h magic
- 作者: Drew Neil,新丈径
- 出版社/メーカー: アスキー・メディアワークス
- 発売日: 2013/08/29
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (15件) を見る
dynamoDBのpartition分割
dynamoDBはstorage sizeとthroughputが大きくなるにつれてpartitonを増やしていく
その際の挙動について調べたのでメモ
partitionとprimary keyの関係について
Partitions and Data Distribution - Amazon DynamoDB
partition分割時の挙動について
Guidelines for Working with Tables - Amazon DynamoDB
1つのpartitonは
- 10GBのデータを保持できる
- readだけなら3000, writeだけなら1000のcapacityをサポートできる
これを超えるとpartitoinは分割される
あるitemがどのpartitionに含まれるかはhash keyの値をhash関数で処理した値によって決まる
To write an item to the table, DynamoDB uses the value of the partition key as input to an internal hash function. The output value from the hash function determines the partition in which the item will be stored.
Guidelines for Working with Tables - Amazon DynamoDB
のdocumentでも説明されている内容によると、partition分割時にはitemが均等に分割されると図を用いて描かれている
1. Allocate two new partitions (P1 and P2).
2. Distribute the data from P evenly across P1 and P2.
3. Deallocate P from the table.
ただ、hash keyが同一であれば同じpartitionに属するはずなのでhash keyの選び方によっては均等に分割されるとは限らないと考えられる、というか均等になるようにhash keyを選ぶべきということか。
ちなみにGlobal Secondary Indexを用いるときも上記の内容を考慮してhash keyを選ぶ必要がある
Guidelines for Global Secondary Indexes - Amazon DynamoDB
疑問点
例えば以下のようなhask keyがあったとする
- hash key = 1, 2, 3, 4のどれかの値
- 各値ごとに含まれるitem数はそれぞれ1000, 2000, 3000, 4000
この場合、partitionを4つに分けるとすれば一つのpartitionが一つのhash keyを担当する形になるのだと思う。
ではこれを2 partitionに分割する場合は?
- hash keyが(1, 4)と(2, 3)の組み合わせでitem数がそれぞれ5000ずつとなるように分割してくれるのだろうか?
- hash keyを若い方から見ていって半分ずつくらいになるところまでが一つのpartitionとなるのだろうか?
- この例だと(1,2,3)と(4)に分割されるという意味
この辺はparition分割の実装次第になるのだろうが詳細に解説しているdocumentは見つけられなかった。