How to set the same value to the matrix of multiple rows and each row with different column numbers without for loop? For example for matrix a:
a=matrix([[1,2,3],
[8,2,9],
[1,8,7]])
row = [1,2,3]
col = [[1,2]
[1,3]
[2,3]]
I want to set a[1,1],a[1,2],a[2,1],a[2,3],a[3,2],a[3,3] to the same value. I know use for loop:
for i in xrange(len(row)):
a[row[i],col[i]] = setvalue
But is there anyway to do this without for loop?
matrix
that you could make with the methodmatrix.setValue(rows, cols, value)
. This would require a loop internally to the matrix class, but not in how you use the method. – Frank Bryce