Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to multiply a given row `i` or column `j` with a scalar?

Tags:

python

numpy

import numpy as np

M = np.matrix([
        [-1,-2,-3],
        [-4,-5,-6]
    ])

print(M)
  1. How to multiply a given row i or column j with a scalar?
  2. How to acces a given column or row as a list?
  3. How to set a given column or row, given a list (of the appropiate length)?
like image 614
Flavius Avatar asked Dec 11 '22 19:12

Flavius


1 Answers

To multiply a particular column:

M[:,colnumber] *= scalar

Or a row:

M[rownumber,:] *= scalar

And of course, accessing them as an iterable is the same thing:

col_1 = M[:,1]

Although, that gives you a new matrix, not a list. Although, honestly, I can't quite seem to figure out all of these operations with matrix objects -- And these don't really seem like matrix type operations. Is there a reason that you're using matrix instead of array objects? If you want matrix multiplication, you can always use np.dot(array_mat1, array_mat2)

like image 70
mgilson Avatar answered Dec 30 '22 14:12

mgilson