Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

python - Using for loop and 2d numpy array, is there a way to reduce the data even more?

The data represents a time-averaged connectivity pattern between EEG electrodes. The midline represents the value 0 because the connection to its own is marked as 0.

# plot the time-averaged connectivity
plt.imshow(time_average,cmap ='jet')
plt.colorbar()
plt.xlabel('channel')
plt.ylabel('channel')

original time-averaged connectivity graph

I am trying to extract the data represented only in the top triangle of the graph using for-loop.

time_average_data_red = [[0]*105 for i in range(105)]

for i in range (105):
    for ii in range(i):
        time_average_data_red[ii][i] = time_average[ii][i]

reduced time-average-data graph

Instead of making the repeating data value as 0 and plotting as above, is there a way to simply make the same graph without the lower bottom triangle of zero values?

Thank you.

question from:https://stackoverflow.com/questions/65847386/using-for-loop-and-2d-numpy-array-is-there-a-way-to-reduce-the-data-even-more

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What about upper triangular matrix

import numpy as np
plt.imshow(np.triu(time_average, 1),cmap ='jet')
...
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...