1

I want to convert this numpy array into a 3 by 3 matrix

array([[3,4,5],
       [5,6,7],
       [2,3,4]])

How to do this in python ?

2 Answers2

1

It's already a matrix. In numpy you can read data as follow:

>>> a
array([[3, 4, 5],
       [5, 6, 7],
       [2, 3, 4]])
>>> a[0] # first line
array([3, 4, 5])
>>> a[1] # second line
array([5, 6, 7])
>>> a[0,1] # value of second col on first line
4
0

It is already a 3x3 numpy array.

>>> import numpy as np
>>> array = np.array([[3, 4, 5],
                      [5, 6, 7],
                      [2, 3, 4]])
>>> print(array.shape)
(3, 3)
Gustavo
  • 668
  • 13
  • 24