[SciPy-User] numpy.random.choice throws AttributeError when called with a list of objects.

Garvin Haslett g_haslett at yahoo.co.uk
Fri Feb 15 14:13:17 EST 2013


The code below results in:
AttributeError: SgCoord instance has no attribute 'ndim'

Given that an example in the documentation operates on an array of strings,
I'd expect numpy.random.choice to work with an array of objects. Is this 
not the case?

-------------------------------

import numpy as np

class SgCoord():
    "A 2D coordinate"
    def __init__(self, x = 0, y = 0):
        self.x = x
        self.y = y
        
if __name__ == '__main__':
    l = []
    l.append(SgCoord(1,1))
    np.array(l)
    np.random.choice(l)




More information about the SciPy-User mailing list