SciPyはPythonのNumpy拡張で構築された数学的アルゴリズムと便利関数のコレクションです。インタラクティブなPythonセッションには、データを操作し可視化するための高度なコマンドとクラスをユーザに提供することで、大きな力を加えることができます。 SciPyではインタラクティブなPythonセッションが、MATLAB、IDL、Octave、R-Lab、SciLabなどのシステムに匹敵するデータ処理およびシステムプロトタイプ作成環境になります。
Python上でSciPyを使用することの利点は、高度なプログラムや特殊アプリケーションの開発にも強力なプログラミング言語を利用できることです。 SciPyを使用した科学的アプリケーションは、世界中の開発者によるソフトウェア環境のさまざまなニッチでの追加モジュールの開発の恩恵を受ける。並列プログラミングからWebおよびデータベースベースのサブルーチンやクラスまでのすべてが、Pythonプログラマーに提供されています。 SciPyの数学ライブラリに加えて、このすべての機能が利用できます。
バージョン | 発売日 |
---|---|
0.19.0 | 2017-03-09 |
0.18.0 | 2016-07-25 |
0.17.0 | 2016-01-22 |
0.16.1 | 2015-10-24 |
0.16.0 | 2015-07-23 |
0.16b2 | 2015-05-24 |
0.16b1 | 2015-05-12 |
0.15.1 | 2015-01-18 |
0.15.0 | 2015-01-11 |
0.14.1 | 2014-12-30 |
0.14.1rc1 | 2014-12-14 |
0.14.0 | 2014-05-03 |
0.14.0rc2 | 2014-04-23 |
0.14.0rc1 | 2014-04-02 |
0.14.0b1 | 2014-03-15 |
0.13.3 | 2014-02-04 |
0.13.2 | 2013年12月7日 |
0.13.1 | 2013-11-16 |
0.13.0 | 2013年10月19日 |
0.13.0rc1 | 2013年10月10日 |
0.12.1 | 2013年10月8日 |
0.12.0 | 2013-04-06 |
0.12.0rc1 | 2013-03-29 |
0.12.0b1 | 2013-02-16 |
0.11.0 | 2012-09-24 |
0.11.0rc2 | 2012-08-12 |
0.11.0rc1 | 2012-07-17 |
0.11.0b1 | 2012-06-12 |
0.10.1 | 2012-02-26 |
0.10.1rc2 | 2012-02-19 |
0.10.1rc1 | 2012-02-10 |
0.10.0 | 2011-11-13 |
0.10.0rc1 | 2011-11-03 |
0.10.0b2 | 2011-09-16 |
0.10.0b1 | 2011-09-11 |
0.9.0 | 2011-02-27 |
テキストエディタやPythonエディタでファイルを作成します( もしそうでなければ SublimeText、Eclipse、NetBeans、SciTe ...がたくさんあります)。
hwld = 'Hello world'
print(hwld)
Python変数は明示的に宣言する必要はありません。変数に等号(=)で値を代入すると、宣言が行われます。
上記2行のコードの出力は、文字列 "Hello World"が表示されることです。
Pythonで書かれた関数は、iPythonでも使用できます。
この場合、IPythonで保存したファイル 'hello_world.py'を以下のように実行することができます:
In [1]: %run hello_world.py
#run file to get output below
Hello world
In [2]: wld
#show what value of wld var is
Out[2]: 'Hello world'
In [3]: %whowld
#display info on variable wld (name/type/value)
Variable Type Data/Info
----------------------------
wld str Hello world
あなたが望むなら、2つの変数、例えばhelloとworldのために1つを使用し、プラス記号(+)を使ってそれらを連結することができます:
h = 'Hello '
w = "world!'
print(h+w)
#this will also output Hello World, only this time with an exclamation mark..
from scipy.sparse import csr_matrix
A = csr_matrix([[1,0,2],[0,3,0]])
>>>A
<2x3 sparse matrix of type '<type 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
>>> A.todense()
matrix([[1, 0, 2],
[0, 3, 0]])
>>> A.toarray()
array([[1, 0, 2],
[0, 3, 0]])
SciPyは基本的な画像操作機能を提供します。ディスクからイメージをnumpy配列に読み込み、numpy配列をイメージとしてディスクに書き込んだり、イメージのサイズを変更したりする機能があります。
次のコードでは、1つのイメージしか使用されません。色づけされ、サイズが変更され、保存されます。オリジナルイメージと結果イメージは次のとおりです。
import numpy as np //scipy is numpy-dependent
from scipy.misc import imread, imsave, imresize //image resizing functions
# Read an JPEG image into a numpy array
img = imread('assets/cat.jpg')
print img.dtype, img.shape # Prints "uint8 (400, 248, 3)"
# We can tint the image by scaling each of the color channels
# by a different scalar constant. The image has shape (400, 248, 3);
# we multiply it by the array [1, 0.95, 0.9] of shape (3,);
# numpy broadcasting means that this leaves the red channel unchanged,
# and multiplies the green and blue channels by 0.95 and 0.9
# respectively.
img_tinted = img * [1, 0.95, 0.9]
# Resize the tinted image to be 300 by 300 pixels.
img_tinted = imresize(img_tinted, (300, 300))
# Write the tinted image back to disk
imsave('assets/cat_tinted.jpg', img_tinted)
Scipyには、C、C ++、Fortranで記述され、使用前にコンパイルする必要がある部分が含まれています。したがって、必要なコンパイラとPython開発ヘッダーがインストールされていることを確認してください。コードをコンパイルすることは、以下で説明する開発ソースからインポートするために、Scipyが追加の手順を必要とすることも意味します。
あなたのアカウントにGithubの主なScipyリポジトリのコピーをフォークし、次にあなたのローカルリポジトリを作成します:
$ git clone git@github.com:YOURUSERNAME/scipy.git scipy
$ cd scipy
$ git remote add upstream git://github.com/scipy/scipy.git
Scipyの開発版をビルドしてテストを実行するには、Pythonのインポートパスを適切に設定して対話型のシェルを作成します。次のいずれかの操作を行います。
$ python runtests.py -v
$ python runtests.py -v -s optimize
$ python runtests.py -v -t scipy/special/tests/test_basic.py:test_xlogy
$ python runtests.py --ipython
$ python runtests.py --python somescript.py
$ python runtests.py --bench
これはScipyを最初に構築するので、最初は時間がかかることがあります。 -n
を指定すると、現在のPYTHONPATHにあるScipy(存在する場合)のバージョンに対してテストが実行されます。
テストの実行にはruntests.pyを使用することをお勧めします。たとえば、インプレースビルドや仮想環境へのインストールなど、さまざまな方法があります。いくつかのテストは非常に遅く、個別に有効にする必要があります。
Ubuntu&Debian
コマンドを実行する
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Ubuntu 12.10以降のバージョンとDebian 7.0以降のバージョンは、現在のSciPyスタック仕様を満たしています。ユーザーは、追加のSciPyパッケージ用にNeuroDebianリポジトリを追加することもできます。
SciPyの最初のリリース、vsn 0.10は2001年8月14日にリリースされました。SciPyの現在のリリース(2016年7月26日に正しい)はv.18(v.18)がすぐにリリースされる0.17(安定版)です。以前のリリースの詳細はこちら