假設array a的size為(2,5),array c的size為(2,),如果要做elementwise multiplication時,我的做法:
(a.T*c).T
但是這個做法需要寫到兩次transpose,式子變長時不易理解。
後來在trace別人的code時,看到了以下的寫法:
a*c[:, np.newaxis]
即可達到相同的效果,且較容易理解。
2013年10月1日
2013年8月10日
[Theano] 在Eclipse中使用GPU執行程式
首先在{HOME}下建立.theanorc檔案,內容如下:
[global] floatX = float32
device = gpu0
[nvcc] fastmath = True
存檔後,退出至{HOME}中。
輸入nvcc指令測試cuda套件是否已經安裝完成。
然後到eclipse隨便建立一個python檔,import theano後,執行該程式, 此時可能會出現以下錯誤:
ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.
這是因為eclipse的pydev套件使用的PATH變數與linux中不同,
用以下指令修正:
window->preferences->PyDev->Interpreter-Python->Environment->New-> Name: PATH, Value: ${env_var:PATH}:/usr/local/cuda-5.0/bin
設定完成後,可在python檔使用
import os
print os.environ['PATH']
確定環境變數修改完成。
[global] floatX = float32
device = gpu0
[nvcc] fastmath = True
存檔後,退出至{HOME}中。
輸入nvcc指令測試cuda套件是否已經安裝完成。
然後到eclipse隨便建立一個python檔,import theano後,執行該程式, 此時可能會出現以下錯誤:
ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.
這是因為eclipse的pydev套件使用的PATH變數與linux中不同,
用以下指令修正:
window->preferences->PyDev->Interpreter-Python->Environment->New-> Name: PATH, Value: ${env_var:PATH}:/usr/local/cuda-5.0/bin
設定完成後,可在python檔使用
import os
print os.environ['PATH']
確定環境變數修改完成。
2013年5月11日
[R] install.packages without graphics
由於我經常使用linux + screen的方式在遠端執行R ,在安裝R套件時無法使用graphics套件來選擇mirror,所以改用以下的方式在console下設定mirror site後,再來安裝套件。
chooseCRANmirror(graphics=FALSE); install.packages("pkgName")即可安裝套件。
2013年3月16日
postgresql備份與還原
OS: Ubuntu 12.04 & Postgresql 9.1
因為備份與還原資料時,需要相當長的時間,因此我所使用的備份與還原的工具都是在screen環境下使用pg_backup備份,psql還原。
備份
備份
- pg_dump -h [host](localhost) -F [format, p: sql script(default), t: tar, c: compress] [資料庫名稱 ] -U [帳號] -f [備份檔名稱.sql] -v
- 以db_chenhh這個帳號,備份investment資料庫,則命令:pg_dump investment -U db_chenhh -f investment_backup.sql
還原
- 命令:psql -f [備份檔名稱.sql] [資料庫] [帳號]
- psql -f investment_backup.sql investment db_chehh
- 命令: pg_restore, 參數與pg_dump相同
- pg_restore -f investment_backup.sql investment
2013年3月9日
更換BLAS implementation
使用openBLAS替換ATLAS(Ubuntu 12.04)
- sudo apt-get install libopenblas-base, libopenblas-dev
- sudo update-alternatives --all
- set
liblapack.so.3gf
to/usr/lib/lapack/liblapack.so.3gf
其它的BLAS替代方案可參考Debian wiki:http://wiki.debian.org/DebianScience/LinearAlgebraLibraries
2013年2月5日
linux新增字型
OS: ubuntu 12.04
新增字型的方法:- 在/usr/share/fonts新增資料夾(e.g. winfonts)
- 將字型檔案copy至/usr/share/fonts/winfonts/
- 執行sudo fc-cache -f -v
2013年1月21日
postgresql連線問題(beta)
- Cdbexception 這是一個連線數超過資料程式庫限制連線數的的問題。
- postgres=# select count(1) from pg_stat_activity; #目前連線數
- postgres=# show max_connections; #系統最大連線數
- postgres=# show superuser_reserved_connections; #保留給superuser的連線數
- 增大postgresql.conf中的參數max_connections或superuser_reserved_connections 值(修改這兩個參數都需要重啟DB)
- 開發程式上檢查連線數是否正常關閉等,應急情況下,可把pg_stat_activity中IDLE的程式移除,kill procpid;
- psql: could not connect to server: Connection refused (0x0000274D/10061) 這個問題一般是以下原因造成的:
- 伺服器沒起來,ps -ef|grep postgres檢視是否存在PG程式
- 監聽問題,cat postgresql.conf|grep listen 檢視監聽位址是否正確
- 服務端高階使用者能進去,其他用戶不行,檢查是否超出最大連線數限制
- 以上都沒問題,伺服器端能連進去,但用戶端不行,這時需要檢視pg_hba.conf檔案
- 以上都沒問題,檢查伺服器端的iptables,開啟防火牆的存取通訊埠
首先檢視一下資料庫內,現在的連線數:
訂閱:
文章 (Atom)