LoginSignup
0
2

More than 5 years have passed since last update.

pythonでNumPyを使って、行列を作ってみよう

Posted at

numpyとは

NumPy(ナムパイまたはナンパイ)は、プログラミング言語Pythonにおいて数値計算を効率的に行うための拡張モジュールである。効率的な数値計算を行うための型付きの多次元配列(例えばベクトルや行列などを表現できる)のサポートをPythonに加えるとともに、それらを操作するための大規模な高水準の数学関数ライブラリを提供する。

参考:【NumPy

いろんな処理を簡単にしてくれるのがnumpyです。


>>> import numpy as np
>>> list1 = [1,2,3,4]
>>> list2 = [5,6,7,8]
>>> lists = [list1,list2]
>>> arr = np.array(lists)
>>> print(arr)
[[1 2 3 4]
 [5 6 7 8]]

同じことは一行でも出来ます


>>> new_arr = np.array([[1,2,3,4],[1,2,3,4]])
>>> new_arr
array([[1, 2, 3, 4],
       [1, 2, 3, 4]])

ポイント!

1:リスト同士を入れるリストを作っている!
2:リスト同士は,で区切る!
3:np.array()を呼んでいる!

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2