From: Alan G I. <ai...@am...> - 2009-03-03 13:41:10
|
You are correct: the try clause now succeeds because downcasting is allowed: >>> x = np.random.random((5,)) >>> x.dtype dtype('float64') >>> x32 = x.astype(np.float32) >>> x32.dtype dtype('float32') How about returning any ndarray untouched? if isinstance(m, numpy.ndarray): return m else: return numpy.array(m,dtype=numpy.float32) I see no need to print an error message: NumPy will report appropriately. Alan Isaac |