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
  • 1
    numpy.matrix()? Commented Aug 4, 2019 at 14:44
  • @Divakar np.matrix is evil. Commented Aug 4, 2019 at 17:25

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.