Hi,
I have a problem with my matrix program. i created and initialized my matrix now i have to file the matrix with values of corr.
i want it to look like this
[1, 0.1, 0.2, 0.3]
[0, 1, 0.4, 0.5]
[0, 0, 1, 0.6]
[0, 0, 0, 1]

file =
corr =

############### initializing the matrix###################
def make_list(size):
mylist = []
for i in range(size):
mylist.append(0)
return mylist

mx = []
def make_matrix(rows,cols):
for i in range(rows):
mx.append(make_list(cols))
return mx

matrix = make_matrix(4, 4)
print(matrix)

##################### filling the matrix###################
for x in range(len(file)):
for y in range(x, len(file)):

if x!= y:
matrix[x][y] = corr(file[x], file[y]) # i want the value of corr here but i dont know what is the syntax
else:
matrix[x][y] = 1

################## printing the matrix #####################

for i in range(len(matrix)):
print matrix

for this program i am getting an error like this
File "symm_matrix.py", line 32, in <module>
matrix[x][y] = corr(file[x], file[y])
TypeError: 'list' object is not callable

please help....

matrix[x][y] = corr(file[x], file[y])
TypeError: 'list' object is not callable

corr = ## list
matrix[x][y] = corr(file[x], file[y]) ## function

You are using corr as both a list and a function. You'll have to rename one of them.

for each iteration i want one value of list corr to be filled in i.e at (file[x], file[y]) i want value of corr filled....

for the first iteration
matrix[x][y] = 0.1 (1st value of corr at position ('d1rfea', 'd1flma'))
next
matrix[x][y] = 0.2 (2nd value of corr at position ('d1rfea', 'd1t9ma'))
and so on..

so i dont know how to do this....

Note the form of this
[1, 0.1, 0.2, 0.3]
[0, 1, 0.4, 0.5]
[0, 0, 1, 0.6]
[0, 0, 0, 1]

that is, part one =
[1 ]
[0, 1 ]
[0, 0, 1]
[0, 0, 0, 1]

part two =
[ 0.1, 0.2, 0.3]
[ 0.4, 0.5]
[ 0.6]
[]

Do the first part, appending an extra zero each time, and then append the second part which is just a counter counting from 0.1 up. But to make it more difficult, you have to append one less item each time. For the first part

matrix = []
for y in range(0,4):
   single_list = [0 for x in range(y)]
   single_list.append(1)  
   print "appending", single_list
   matrix.append(single_list)
print matrix
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.