Ejemplo n.º 1
0
def orng2ma(aExampleTable):
    """Converts orange.ExampleTable to MA.array based on the attribute values.
    rows correspond to examples, columns correspond to attributes, class values are left out
    missing values and attributes of types other than orange.FloatVariable are masked
    """
    vals = aExampleTable.native(0, substituteDK="?", substituteDC="?", substituteOther="?")
    ma = MA.array(vals, Numeric.PyObject)
    if aExampleTable.domain.classVar != None:
        ma = ma[:,:-1]
    mask = MA.where(MA.equal(ma, "?"), 1, 0)
    for varIdx, var in enumerate(aExampleTable.domain.attributes):
        if type(var) != orange.FloatVariable:
            mask[:,varIdx] = Numeric.ones(len(aExampleTable))
    return MA.array(MA.array(ma, Numeric.PyObject, mask=mask).filled(1e20), Numeric.Float, mask=mask)
Ejemplo n.º 2
0
def orng2ma(aExampleTable):
    """Converts orange.ExampleTable to MA.array based on the attribute values.
    rows correspond to examples, columns correspond to attributes, class values are left out
    missing values and attributes of types other than orange.FloatVariable are masked
    """
    vals = aExampleTable.native(0,
                                substituteDK="?",
                                substituteDC="?",
                                substituteOther="?")
    ma = MA.array(vals, Numeric.PyObject)
    if aExampleTable.domain.classVar != None:
        ma = ma[:, :-1]
    mask = MA.where(MA.equal(ma, "?"), 1, 0)
    for varIdx, var in enumerate(aExampleTable.domain.attributes):
        if type(var) != orange.FloatVariable:
            mask[:, varIdx] = Numeric.ones(len(aExampleTable))
    return MA.array(MA.array(ma, Numeric.PyObject, mask=mask).filled(1e20),
                    Numeric.Float,
                    mask=mask)
Ejemplo n.º 3
0
def getPositions(m, val):
    """Input: arbitrary (masked) array and a value from that array;
    Output: array of positions of the given value in a flat m;
    """
    m = MA.asarray(m)
    return Numeric.compress(MA.equal(MA.ravel(m),val), Numeric.arange(Numeric.multiply.reduce(m.shape)))