I have a list of 49 values. I've created an array of this list, to print in a matrix, with sequence identifiers from a fasta file. Here is the code:
print my_plist
print len(my_seq_labels)
row_col = len(my_seq_labels)
size =7
myarray = [my_plist[w:w+size+1] for w in range(0, len(my_plist), size)]
print "\t\t",
for j in range(row_col):
print my_seq_labels[j],"\t",
print
for i in range(row_col):
print my_seq_labels[i],"\t",
for j in range(row_col):
print "%.4f" % myarray[j][i],"\t\t",
print
This is the output:
[0.0, 0.006535947712418301, 0.00980392156862745, 0.08496732026143791, 0.08169934640522876, 0.08169934640522876, 0.13398692810457516, 0.006535947712418301, 0.0, 0.00980392156862745, 0.08496732026143791, 0.08169934640522876, 0.08169934640522876, 0.13398692810457516, 0.00980392156862745, 0.00980392156862745, 0.0, 0.0784313725490196, 0.07516339869281045, 0.07516339869281045, 0.12745098039215685, 0.08496732026143791, 0.08496732026143791, 0.0784313725490196, 0.0, 0.0032679738562091504, 0.0032679738562091504, 0.13398692810457516, 0.08169934640522876, 0.08169934640522876, 0.07516339869281045, 0.0032679738562091504, 0.0, 0.006535947712418301, 0.13071895424836602, 0.08169934640522876, 0.08169934640522876, 0.07516339869281045, 0.0032679738562091504, 0.006535947712418301, 0.0, 0.13071895424836602, 0.13398692810457516, 0.13398692810457516, 0.12745098039215685, 0.13398692810457516, 0.13071895424836602, 0.13071895424836602, 0.0]
7
410488935 410488927 410488931 410488939 410488937 410488923 410488933
410488935 0.0000 0.0065 0.0098 0.0850 0.0817 0.0817 0.1340
410488927 0.0065 0.0000 0.0098 0.0850 0.0817 0.0817 0.1340
410488931 0.0098 0.0098 0.0000 0.0784 0.0752 0.0752 0.1275
410488939 0.0850 0.0850 0.0784 0.0000 0.0033 0.0033 0.1340
410488937 0.0817 0.0817 0.0752 0.0033 0.0000 0.0065 0.1307
410488923 0.0817 0.0817 0.0752 0.0033 0.0065 0.0000 0.1307
410488933 0.1340 0.1340 0.1275 0.1340 0.1307 0.1307 0.0000
How can this code be modified in the for loop where the array prints, to print in an upper triangular matrix? (as well as lower)
Any help is appreciated.
May be this can help: numpy.triu (triangle-upper) and numpy.tril (triangle-lower).