らんだむな記憶

blogというものを体験してみようか!的なー

Python

数理最適化

Pythonによる数理最適化入門 ちょっと気になるな。

SettingWithCopyWarning

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:27: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/in…

unicodedata.nameの逆

import unicodedata for c in "abcde": print(unicodedata.name(c), unicodedata.lookup(unicodedata.name(c))) へー。

pyenv install 3.6.8

python 3.6環境 - らんだむな記憶と同じ理由だろうけど、Colaboratoryのpythonのバージョンも3.6.8だった。なんとなくColaboratoryと同じような環境をローカルにもう1つ作ってみる。 pyenvでやってみるも微妙なログが出てつらい・・・ zipimport.ZipImportEr…

lru_cache

うっ・・・こんなのがあるのか・・・。 Dice -- from Wolfram MathWorldにあるような面が$s$個のサイコロを$n$個転がした時に面の総和が$p$になる確率・・・をpythonで実装したくなった。 数日考えて、漸化式による解法を思いつくが(動的計画法と言うらしい…

python setup.py uninstall

setup.pyを用いてインストールしたモジュールのアンインストール方法 - Qiita python setup.py install --record files.txt cat files.txt | xargs rm -rf なんか面倒くさい・・・

1%のガチャを100回引く

>>> 1-(99./100)**100 0.6339676587267709 と >>> 1-10**(100*(2*math.log10(3)+math.log10(11)-2)) 0.6339676587267531 あれ・・・。意外と一致するな・・・。今時は雑な計算させても丸め誤差を抑えてくれるのかな・・・

インスタンスメソッド置換

#! /usr/bin/env python # -*- coding: utf-8 -*- class Base(object): def print_num(self): print(self.number()) def number(self): return 3 def new_number(self): return self._old_number() + 5 def replace_number(): if not hasattr(Base, "_old_nu…

matplotlibで日本語表示

matplotlibで描画したグラフの文字化けを解消する - Qiitaという感じのことをすれば良いらしい。

Python 機械学習プログラミング 第3章(2)

ppn.fit(X_train_std, y_train) の部分をpython - Is it possible to get test scores for each iteration of MLPClassifier? - Stack Overflowを参考に書き換えて scores_train = [] for _ in range(40): ppn.partial_fit(X_train_std, y_train, np.unique(…

Python 機械学習プログラミング 第3章(1)

https://github.com/rasbt/python-machine-learning-book-2nd-edition/blob/master/code/ch03/ch03.py#L130のところで DeprecationWarning: n_iter parameter is deprecated in 0.19 and will be removed in 0.21. Use max_iter and tol instead. が出ちゃう…

ファンシーインデックス

Numpyのファンシーインデックス(Fancy Index)で配列を自由に操作する - Qiita うへぇ・・・ import numpy as np y = np.array(range(300,300+100)) rgen = np.random.RandomState(1) randomly_permutated_y = y[rgen.permutation(len(y))]でランダムに並んだ…

jupyter notebook

IPython Notebook - らんだむな記憶でも少し触れたが、jupyter notebook で外部からの接続を許可する - Qiitaを参考に設定し直す。 %matplotlib inlineを毎回書かなくて済む方法 - Qiita MacでJupyter Notebookを使ってみる - Qiita How to set InteractiveS…

OpenOfficeのpythonマクロ(2)

# -*- coding: utf-8 -*- FONT_NAME_ASIAN = u"源ノ明朝 SemiBold" # https://wiki.openoffice.org/wiki/JA/Documentation/BASIC_Guide/Structure_of_Text_Documents def change_text_font(text, font_name): enumeration = text.createEnumeration() while …

OpenOfficeのpythonマクロ(1)

%appdata%\OpenOffice\4\user\Scripts\python の下に python スクリプトを置くと、OpenOffice アプリの[ツール]→[マクロ]→[マクロの管理]→[Python]の下にマクロとして現れる。 # -*- coding: utf-8 -*- ctx = XSCRIPTCONTEXT.getComponentContext() smgr = c…

Windowsでのpythonの2.7系と3.x系の共存

WindowsにPython2.7とPython3.7が共存できるようにインストールする - Qiita のようにすればいけるみたい。

画像検索

Googleの画像検索APIを使って画像を大量に収集する タイトルから絵画を検索したいなーと。 GitHub - lucasdavid/wikiart: Full retriever for art and metadata in http://wikiart.org/ こーゆーほうがいいかもしれないけど。

読み取ってそのまま書き出す

こんな感じかな。むずい・・・ #! /usr/bin/env perl while (<STDIN>) { print; } #! /usr/bin/env ruby while line=gets print end #! /usr/bin/env python import sys while True: line=sys.stdin.read() if line: sys.stdout.write(line) else: break</stdin>

wheel

【Python】pipとwheelとか今更に読んでみる。ふーん。easy_installは古いものだったのか。こういう情報ってどっから見つけるのかな。 wheelを作る気はないけど自分でビルドした OpenCV モジュールの wheel を作るとか参考にしたらちょっと変わったこともでき…

plenv installできない

今更perlって・・・ってのもあるが・・・ [対処法] 599 Internal Exception, https://fastapi.metacpan.org/v1/release/_searchにあるようにMozilla::CA関連でplenvの使用に支障があることも。

anyenv+pyenv

気持ちを新たにUbuntu 18.04 LTSにanyenv+pyenv環境を作る。 anyenvで開発環境を整える - Qiitaでにょろっとanyenvを入れる。 【pyenv】ubuntu16.04でのpython環境の構築 - Qiita Ubuntu 15.10 で pyenv install 3.5.0 したら pip がインストールできなくて…

pythonとバイナリ

Cで書きたくない・・・というかコンパイルめんどいのでpythonでバイナリを解析しようかと。 データ構造がない場合はちょっとずつ読み込んで・・・となるかもしれないが、わりとかっちりした構造があるならPythonでバイナリをあつかうためのTipsのようにctype…

数学的区間のpythonにおける表現

Using intervals — PyInterval 1.2.1.dev0 documentation pyinterval · PyPI PyIntervalが使えそうかなぁ

文字界隈におけるニシキヘビの生態系について

Origins of Python in Type Design — TypeDrawers ふむ...。

struct.unpackのようなC++的方法

Python's struct.pack/unpack equivalence in C++ - Stack Overflow serialization - pack/unpack functions for C++ - Stack Overflow そんなものはない。ntohlとかで頑張れ的世界。

任意の属性

#! /usr/bin/env python # -*- coding: utf-8 -*- class AnyAttributes(object): i = 0 def __getattr__(self, name): value = AnyAttributes.i setattr(self, name, value) AnyAttributes.i += 1 return value def main(): obj = AnyAttributes() print obj…

pyenv-virtualenv(2)

pyenv-virtualenv - らんだむな記憶 気がつかなかったけど、 eval "$(pyenv virtualenv-init -)" して以来、bashでenterを押した時にプロンプトが返ってくるまでの時間が遅くなっている...。

pyenv-virtualenv

pyenv-virtualenvでディレクトリ単位のpython環境構築 - Qiita pyenv と pyenv-virtualenv で環境構築 - Qiita Pythonの仮想環境構築(2017年版) pyenvとpyenv-virtualenvとvirtualenvとvirtualenvwrapperとpyvenvとvenv - Qiita 辺りを読んで考えた。 git cl…

FreeTypeで文字を書く(2)

FreeTypeで文字を書く - らんだむな記憶の続きがほんのりやりたくなった。 freetype-py/agg-trick.py at master · rougier/freetype-py · GitHubがいいサンプルなので以下のようにしてみた。いい感じ。 def save_image(face, gid): face.load_glyph(gid) bit…

PageBot

GitHub - TypeNetwork/PageBot: Scripted page layout program, as application inside Drawbot.にスクリプトで制御可能なページレイアウトプログラムがある。DrawBot Documentation — DrawBot 3.97の中から動かす形なので単独では動作しない。どうもインス…