Search code examples
pythonnumpypycharmsom

Running Growing Self-Organizing Map(GSOM) GitHub Implementation failed with AttributeError: 'numpy.ndarray' object has no attribute 'iteritems'


I have got some codes of Growing Self-Organizing Map(GSOM) from GitHub (All required information for understanding the Mechanism of GSOM has described in the implementation's Documentation).

I tried to run it in PyCharm version 2018.1.4 with the Python 3.6 as Project Interpreter, but I came across this error:

ValueError: too many values to unpack (expected 2)

The above error is related to the constructor of the GSOM class and specifically in the below loop:

        for fn,t in dataset:
            arr = scipy.array(t)
            self.data.append([fn,arr])

I know that this error is a common error in loops and I have to say that I tried most of solutions that i have found in stack overflow.

For example I used the functions like iteritems() ,but I have confronted with the following error:

AttributeError: 'numpy.ndarray' object has no attribute 'iteritems'

The Python Program I have developed for applying this implementation is:

from gsom import GSOM
import numpy as np
dataset = np.array([
          [1., 0., 0.],
          [1., 0., 1.],
          [0., 0., 0.5],
          [0.125, 0.529, 1.0],
          [0.33, 0.4, 0.67],
          [0.6, 0.5, 1.0],
          [0., 1., 0.],
          [1., 0., 0.],
          [0., 1., 1.],
          [1., 0., 1.],
          [1., 1., 0.],
          [1., 1., 1.],
          [.33, .33, .33],
          [.5, .5, .5],
          [.66, .66, .66]])
SF = 0.5
Test = GSOM(dataset, SF)

I'm going to apply this implementation to visualize High-Dimensional Data with a 2-Dimension Grid.

The dataset I used is 3-Dimensional (has three attribute) and is a simple example to understand the performance of the GSOM's functionality.

The original dataset that I will use, has more than 20 attributes.


Solution

  • For solving this error after a complete 4 hours search!! i found that i have to use below code:

    for fn, t in np.ndenumerate(dataset):
        arr = scipy.array(t)
        self.data.append([fn, arr])
    

    ndenumerate() is the key function from numpy to loop in a numpy ndarray in a right way.

    Thanks Me! :)