Conversion of matlab import containing objects into 3d array

Hi all, I'm trying to import data from a matlab file using scipy.io.loadmat. One of the variables in the file imports as an array of shape (51,) of dtype object, with each element being an array of shape (23,100) of dtype float. How do I convert this array into a single array of dtype float with shape (51,23,100)? objarr.astype(float), which I thought might work (from [1]), gives me the error "ValueError: setting an array element with a sequence.". [1] http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/2998408 Many thanks for any help, Angus. -- AJC McMorland Post-doctoral research fellow Neurobiology, University of Pittsburgh

HI,
I'm trying to import data from a matlab file using scipy.io.loadmat. One of the variables in the file imports as an array of shape (51,) of dtype object, with each element being an array of shape (23,100) of dtype float. How do I convert this array into a single array of dtype float with shape (51,23,100)? objarr.astype(float), which I thought might work (from [1]), gives me the error "ValueError: setting an array element with a sequence.".
I guess that your array started life as a matlab cell array of shape (51,1). As far as I know you'd have to convert long-hand: np.concatenate(list(a), axis=0).reshape((51,23,100)) sort of thing... Best, Matthew

On Feb 5, 2010, at 2:12 PM, Angus McMorland wrote:
Hi all,
I'm trying to import data from a matlab file using scipy.io.loadmat. One of the variables in the file imports as an array of shape (51,) of dtype object, with each element being an array of shape (23,100) of dtype float. How do I convert this array into a single array of dtype float with shape (51,23,100)? objarr.astype(float), which I thought might work (from [1]), gives me the error "ValueError: setting an array element with a sequence.".
[1] http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/2998408
Something like this (assuming your array is named 'a') np.array(list(a), dtype=float) -Travis
participants (3)
-
Angus McMorland
-
Matthew Brett
-
Travis Oliphant