Numpy-matrix-library

提供:Dev Guides
移動先:案内検索

NumPy-マトリックスライブラリ

NumPyパッケージには、マトリックスライブラリ numpy.matlib が含まれています。 このモジュールには、ndarrayオブジェクトの代わりに行列を返す関数があります。

matlib.empty()

  • matlib.empty()*関数は、エントリを初期化せずに新しい行列を返します。 この関数は、次のパラメーターを取ります。
numpy.matlib.empty(shape, dtype, order)

どこで、

Sr.No. Parameter & Description
1

shape

  • int* または新しいマトリックスの形状を定義する *int* のタプル
2

Dtype

オプションです。 出力のデータ型

3

order

CまたはF

import numpy.matlib
import numpy as np

print np.matlib.empty((2,2))
# filled with random data

それは次の出力を生成します-

[[e-314,   4.24399158e-314]
 [ 4.24399158e-314,   2.12199579e-314]]

numpy.matlib.zeros()

この関数は、ゼロで満たされた行列を返します。

import numpy.matlib
import numpy as np
print np.matlib.zeros((2,2))

それは次の出力を生成します-

[[numpy.matlib.ones()

This function returns the matrix filled with 1s.

[source,prettyprint,notranslate]

import numpy.matlib import numpy as np print np.matlib.ones((2,2))

It will produce the following output −

[source,result,notranslate]

[[numpy.matlib.eye()

この関数は、対角要素に沿って1を持ち、他の場所にゼロを持つ行列を返します。 この関数は、次のパラメーターを取ります。

numpy.matlib.eye(n, M,k, dtype)

どこで、

Sr.No. Parameter & Description
1

n

結果の行列の行数

2

M

列数、デフォルトはn

3

k

対角線のインデックス

4

dtype

出力のデータ型

import numpy.matlib
import numpy as np
print np.matlib.eye(n = 3, M = 4, k = 0, dtype = float)

それは次の出力を生成します-

[[numpy.matlib.identity()

The *numpy.matlib.identity()* function returns the Identity matrix of the given size. An identity matrix is a square matrix with all diagonal elements as 1.

[source,prettyprint,notranslate]

import numpy.matlib import numpy as np print np.matlib.identity(5、dtype = float)

It will produce the following output −

[source,result,notranslate]

[[numpy.matlib.rand()

  • numpy.matlib.rand()*関数は、ランダムな値で満たされた指定サイズの行列を返します。

import numpy.matlib
import numpy as np
print np.matlib.rand(3,3)

それは次の出力を生成します-

[[Note* that a matrix is always two-dimensional, whereas ndarray is an n-dimensional array. Both the objects are inter-convertible.

==== Example

[source,prettyprint,notranslate]

import numpy.matlib import numpy as np

i = np.matrix( '1,2; 3,4')print i

It will produce the following output −

[source,result,notranslate]

[[例

import numpy.matlib
import numpy as np

j = np.asarray(i)
print j

それは次の出力を生成します-

[[Example

[source,prettyprint,notranslate]

import numpy.matlib import numpy as np

k = np.asmatrix(j)kを出力

It will produce the following output −

[source,result,notranslate]

[[