I have a python code in which I have to convert a 2D array to a 2D matrix so that I can use it to calculate inverse.For that I am using numpy.matrix(array) but it is not working. Can anyone tell how to convert a 2D array to a numpy matrix? The array consists of all float numbers
如果a
是你的数组,则np.asmatrix(a)
是一个矩阵。
If you have a list of lists (as you mentioned), you need to convert it first to a numpy array; see how to convert 2d list to 2d numpy array?
A short example is given here:
import numpy as np
a = [[ 0. +0.j, 1.j, 2. -2.j],
[ 4. -4.j, 5. -5.j, 6. -1.j],
[ 8. -8.j, 9. -9.j, 10.]]
b = np.matrix(np.array(a))
b_inv = np.linalg.inv(b)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.