0

I am trying to extract a python numpy array of euclidean distances. I already have the values properly imported and distances calculated, and they are already in a visual heat map, but I do not know how to extract the values in a simple array to do further analyses on.

This is the code for creating a 5 (regions) x 4 (condition) matrix for all subjects:

import matplotlib.pyplot as plt
import seaboard as sns
for i in range (0, 41):
    subject=result[i]
    sns.heatmap(subject, annot=True, cmap='RdYlBu_r, yticklabels=['Anxiety', 'Empathy', 'Dominance', 'Unlabeled'],xticklabels=['Cuneus','SPL','Lingual','Cingulate', 'IFG'])
plt.show()

This is the code for calculating the Euclidean distance between each condition in 5 dimensional space for each subject:

for i in range(0,41):
    subject=result[i]
    s_rdm=pdist(subject, 'euclidean')
    squareform(s_rdm)
    sns.heatmap(squareform(s_rdm), annot = True, cmpa="RdYlBu_r', yticklabels=['Anxiety', 'Empathy','Dominance','Unlabeled'], xticklabels=['Anxiety', 'Empathy','Dominance','Unlabeled'])
plt.show()

I am not getting errors—these correctly calculate the distances for each subject. By including "annot = True", each matrix cell has the corresponding value. What I do NOT know how to do is save these distances in an array for future analyses.

b1234
  • 63
  • 7
  • Something is wrong with the quoting in your code, as indicated by the incorrect color rendering above. – jmd_dk Oct 23 '17 at 18:22
  • maybe I'm not understanding your question correctly but can you just do `arr = squareform(s_rdm)` and then `sns.heatmap(arr...`, where arr is the data you want to do future analyses with? – Vince W. Oct 23 '17 at 18:55
  • Well I already have the heat map with/based on the distance values for every cell, but I don't know how to extract those numeric values in an array. @VinceW. – b1234 Oct 23 '17 at 19:13
  • I figured this out by fixing really small oversight—print (s_rdm) was missing. Then I just used numpy to save the text. – b1234 Oct 23 '17 at 20:29
  • I see. By extract to an array you meant save in a file? – Vince W. Oct 23 '17 at 21:54
  • yes, that is what i meant. I will say that clearly in the future! @VinceW. – b1234 Oct 23 '17 at 22:01
  • Well, I meant both, I needed to extract and then save in a file. @VinceW. – b1234 Oct 23 '17 at 22:03

0 Answers0