2

My problem is exactly what the title says: I have a numpy array of integers and wish to convert it into an Orange table with discrete values. If I follow these steps, it fails:

import numpy as np
import Orange
a = np.arange(100).reshape((10,10)).astype(np.int8)
fields = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')
d = Orange.data.Domain([Orange.feature.Discrete(x) for x in fields])
t = Orange.data.Table(d, a)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-230-f9b4755dcfba> in <module>()
----> 1 t = Orange.data.Table(d, a)

ValueError: Invalid value for a Discrete variable.

I don't wish to use an intermediate physical file (to be honest I tried using a "virtual" file through cStringIO.StringIO but I couldn't pass it correctly as an argument to Orange.data.Table(), since it expects the file name, not the file).

Is there something I can do to achieve it (apart form the intermediate physical file which is one obvious-but-not-elegant-at-all solution)?

PS I've tried also reshaping the numpy array into string, but it errs by giving:

AttributeError: Converting arrays of type 'S' is not supported (use one of 'bBhHiIlLfdc')
Charles
  • 50,943
  • 13
  • 104
  • 142
mamalos
  • 97
  • 10
  • Refer to function `series2descriptor` [here](http://stackoverflow.com/questions/26320638/converting-pandas-dataframe-to-orange-table) – TurtleIzzy Oct 23 '14 at 01:37

1 Answers1

0

You can mmap your array to a file and then have orange read your mmap'ed file. Alternatively you may have some luck converting your np array to a python array and then reading that from orange.

Clarus
  • 2,259
  • 16
  • 27
  • Claris, thanks for your answer, but it is very abstract. Could you elaborate on your comments by giving an example for each alternative? – mamalos Jun 12 '14 at 13:47