## Orange SOM U-Matrix

6 posts
• Page

**1**of**1**### Orange SOM U-Matrix

Is there some tutorial how to get U-Matrix with python. There is a tutorial to get SOMMap but nothing for U-Matrix. In visualizer I can see the U-Matrix but I don't know how to print it out in Python.

Here is my code to print the nodes into file:

Is this the right way to making a U-Matrix object ?

I need a for loop to print the values from the U-Matrix into the file so I can later show it on a webpage.

Here is my code to print the nodes into file:

- Code: Select all
`#!C:/Python27`

import Orange

import random

random.seed(0)

r = 4

c = 4

som = Orange.projection.som.SOMLearner(map_shape=(r, c), initialize=Orange.projection.som.InitializeRandom)

map = som(Orange.data.Table("input.tab"))

print map[0,0].instances

str = ''

filename = "output.tab"

FILE = open(filename,"w")

for i in range(0, r):

for j in range(0, c):

for e in map[i, j].instances:

str = '%s' % e

FILE.writelines(str + '\n')

FILE.close()

Is this the right way to making a U-Matrix object ?

- Code: Select all
`test = Orange.projection.som.get_u_matrix(map)`

I need a for loop to print the values from the U-Matrix into the file so I can later show it on a webpage.

### Re: Orange SOM U-Matrix

Kristo36 wrote:Is this the right way to making a U-Matrix object ?

- Code: Select all
`test = Orange.projection.som.get_u_matrix(map)`

Yes.

### Re: Orange SOM U-Matrix

But after I make the U-Matrix object how can I iterate through the Nodes like in the SOMLearner object?

### Re: Orange SOM U-Matrix

You can't get the nodes from the U-matrix (it is a plain numpy.ndarray). You have to map the corresponding nodes from the SOMMap to the U-matrix yourself (i.e. every map[i, j] node corresponds to u_matrix[i*2, j*2] entry in the U-matrix).

### Re: Orange SOM U-Matrix

Thank you for the help Ales. It's so simple, but I just started to learn this and didn't have a clue.

6 posts
• Page

**1**of**1**