網頁

2019年4月22日 星期一

終端機底部出現(base)

$ vi ~/.zshrc

$ vi ~/.bashrc

在最後一行加入
conda deactivate

$ source ~/.zshrc

$ source ~/.bashrc

2019年4月21日 星期日

ubuntu 18.04 install pytorch

$ conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

如果無法安裝的話要rm -rf anaconda3,重新安裝anaconda



參考
https://pytorch.org/get-started/locally/

ubuntu 18.04 install opencv

$ sudo apt update
$ sudo apt install python3-opencv
$ pip install opencv-python


$ pip install --upgrade pip
$ pip install opencv-python

確認
$ python3
>>> import cv2
>>> cv2.__version__

參考
https://www.youtube.com/watch?v=cGmGOi2kkJ4

Python __future__

Python在某個版本中出現了新的功能,而且這個特性和當前版本不相容,也就是它在該版本中不是語言標準,那如果想要使用的話,就需要從future模組匯入。一般常用如from __future__ import absolute_import, print_function, division。

from __future__ import absolute_import:在 3.0 以前的舊版本中啟用相對匯入等特性所必須的 future 語句。

ex.
相對匯入:在不指明 package 名的情況下匯入自己這個 package 的模組,比如一個 package 下有 test1.py 和 test2.py 兩個檔案,在 test1.py 裡from . import test2 即是相對匯入 test2.py。
絕對匯入:指明頂層 package 名。比如 import paname,Python 會在sys.path 裡尋找所有名為 paname的頂層模組。



print_function:python2.x中print不需要括號,而在python3.X中則需要。

division:Python在2.x的整數相除,例如4/3,會得到整數1的答案,可是在Python3.x都會得到浮點數。

Python libraries for Chemistry

scikit-chem (https://github.com/richlewis42/scikit-chem) and RDKit (https://github.com/rdkit/rdkit)提供了一組Python library用於設計化學分析工作流程、預測常見功能以及在數據格式之間進行轉換。

2019年4月17日 星期三

Python multiprocessing Pool()

http://kdh74616.blogspot.com/2017/05/python-multiprocessing-pool.html

Julia Taiwan 中文文件

https://docs.juliatw.org/latest/manual/getting-started/

Mozilla推出瀏覽器Python直譯器,提供完整資料科學主流套件

Mozilla公開了能夠在瀏覽器上執行的Python直譯器Pyodide,Pyodide為一項實驗性質的Python計畫,不需要遠端kernel,就能夠在瀏覽器上運行,Mozilla的資料工程師Mike Droettboom稱Pyodide,是能夠完全在瀏覽器上運行的標準Python直譯器。

Pyodide的靈感來自Mozilla的另一個計畫Iodide,Iodide是用最領先的網頁技術,為資料科學實驗和溝通打造的工具,被設計為在瀏覽器上執行資料科學的運算,不幸的是,瀏覽器普遍的語言JavaScript並沒有成熟、一系列的資料科學函式庫,針對數值運算上,也缺少了許多有用的功能,像是運算子超載(operator overloading)。

而Mozilla打造了Pyodide,讓使用者能夠使用完全標準的Python的直譯器,也能存取瀏覽器網頁的API。雖然Pyodide並非首創在瀏覽器上執行的Python直譯器,許多開源項目也是將Python帶到瀏覽器上,像是Transcrypt、Brython、Skulpt和PyPyJs,但是其他項目並沒有像Pyodide,提供完整資料科學主流的套件,包含NumPy、Pandas、Scipy、 Matplotlib。

網址
https://hacks.mozilla.org/2019/04/pyodide-bringing-the-scientific-python-stack-to-the-browser/



參考
https://www.ithome.com.tw/news/130046?fbclid=IwAR09j5IjcZa-YjMnqasnO0YwlFczvRXb0cGoEeq7y_Ehjh7vsBjwwXdAznc

Mac zsh: command not found zsh 所有命令在終端失效

$ PATH=/bin:/usr/bin:/usr/local/bin:${PATH}
$ export PATH


參考
https://www.jiloc.com/43492.html

2019年4月12日 星期五

Getting started with Data Analysis with Python Pandas

https://medium.com/@sukruyavuz96/getting-started-to-data-analysis-with-python-pandas-with-titanic-dataset-a195ab043c77?fbclid=IwAR1rE9j_iJOcteYfa05fc-cLVYw_aS6F1MrwAkJuaqfkUyhbbx9s3rH2mtk

pandas.DataFrame.apply基本用法
https://riptutorial.com/zh-TW/pandas/example/23648/pandas-dataframe-apply-basic-usage
https://zhuanlan.zhihu.com/p/42756654

常用屬性或方法(3)Data Frame
https://ithelp.ithome.com.tw/articles/10185922

python pandas 中 loc & iloc 用法區別
https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/462517/

Python join()方法
http://www.runoob.com/python/att-string-join.html

A Quick Guide to Format String in Python

https://www.techbeamers.com/python-format-string-list-dict/?fbclid=IwAR1d9g9ccMwZq1utkS3fpbo-IiubR1L17xkfNjBFQTP6Osx2AMal8eqZxzI

Reading and Writing Files in Python

https://realpython.com/read-write-files-python/

Python Loops

https://realpython.com/python-for-loop/
https://realpython.com/python-while-loop/
https://docs.python.org/3.8/tutorial/controlflow.html#for-statements

Dealing with TensorFlow incompatibility with Python 3.7 for Mac OSX

1. 安裝anaconda
最新版本已經更新到Python 3.7

2. TensorFlow目前(截至2019年1月)不支持Python 3.7。 所以你必須執行以下命令:
$ conda create --name tensorflow python=3.6

在詢問"Proceed ([y]/n)?"之前如果有出現
==> WARNING: A newer version of conda exists. <==
  current version: 4.6.8
  latest version: 4.6.11

請先選n,然後重新執行
$ conda update -n base -c defaults conda
$ conda create --name tensorflow python=3.6

3. 要進入tensorflow環境,必須使用以下命令
$ source activate tensorflow

如果安裝完要退出的話
$ deactivate

4. 安裝Jupyter
$ conda install jupyter

否則在執行後面python -m ipykernel install --user --name tensorflow --display-name "Python 3.6 (tensorflow)"會出現
/anaconda3/envs/tensorflow/bin/python: No module named ipykernel

5. 最後執行以後命令
$ pip install --upgrade sklearn
$ pip install --upgrade pandas
$ pip install --upgrade pandas-datareader
$ pip install --upgrade matplotlib
$ pip install --upgrade pillow
$ pip install --upgrade requests
$ pip install --upgrade h5py
$ pip install --upgrade pyyaml
$ pip install --upgrade psutil
$ pip install --upgrade tensorflow==1.12.0
$ pip install --upgrade keras==2.2.4

6. 將新的tensorflow環境鏈接到Jupyter,以便您可以選擇它作為Kernal。 始終確保從3.6內核運行Jupyter筆記本。
$ python -m ipykernel install --user --name tensorflow --display-name "Python 3.6 (tensorflow)"

7. 檢查版本
test1.py


$ python3 test1.py


8. 確認效能
test2.py


$ python3 test2.py


雖然有出現
2019-04-12 10:31:28.259411: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

如果覺得礙眼,解決方式是在code裡加入兩行
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

或者在~/.zshrc
export TF_CPP_MIN_LOG_LEVEL=2

參考
https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u
https://epsilonx.cn/blog/init-tensorflow-in-macOS/

9. 測試
https://github.com/keras-team/keras/blob/master/examples/mnist_mlp.py

10. 結論
以上的安裝是為了讓tensorflow搭建在Python 3.6的環境




參考
https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class01_intro_python.ipynb

2019年4月5日 星期五

Python Closure

當我們呼叫function時,它會記住decorator()函式中的argument。 這在Python中稱為closure,例如:



參考
https://data-flair.training/blogs/python-decorator/

Python Scopes and Namespaces

以下內容是要解釋Python document裡9.2.的內容(Python Scopes and Namespaces)