sepandhaghighi/pycm

Casting

sepandhaghighi opened this issue · 0 comments

Description

Casting ConfusionMatrix object to list and dict

Steps/Code to Reproduce

>>> from pycm import *
>>> cm = ConfusionMatrix([1,2,3,4],[1,1,3,4])
>>> cm.matrix
{1: {1: 1, 2: 0, 3: 0, 4: 0}, 2: {1: 1, 2: 0, 3: 0, 4: 0}, 3: {1: 0, 2: 0, 3: 1, 4: 0}, 4: {1: 0, 2: 0, 3: 0, 4: 1}}

Expected Behavior

>>> dict(cm)
{1: {1: 1, 2: 0, 3: 0, 4: 0}, 2: {1: 1, 2: 0, 3: 0, 4: 0}, 3: {1: 0, 2: 0, 3: 1, 4: 0}, 4: {1: 0, 2: 0, 3: 0, 4: 1}}
>>> list(cm)
[(1, {1: 1, 2: 0, 3: 0, 4: 0}), (2, {1: 1, 2: 0, 3: 0, 4: 0}), (3, {1: 0, 2: 0, 3: 1, 4: 0}), (4, {1: 0, 2: 0, 3: 0, 4: 1})]

Actual Behavior

>>> dict(cm)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    dict(cm)
TypeError: 'ConfusionMatrix' object is not iterable
>>> list(cm)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    list(cm)
TypeError: 'ConfusionMatrix' object is not iterable

Operating System

Windows 10

Python Version

Python 3.5.2

PyCM Version (Use : pycm.__version__)

3.3