python - Is there any possibilty to convert recarray to ndarray and change ndim? -
I expected to recara with the matplotlib.mlab.csv2rec function that it would have 2 dimensions like 'x', but 'wi' Is there a way to get x from x?
& gt; & Gt; & Gt; Np & gt; & Gt; & Gt; Date Time By Import Date & gt; & Gt; & Gt; X = np.array ([(Date (2000,1,1), 0,1) ... ... (Date (2000,1,1), 1,1), ... (Date (2000, 1, 1), 1.0, ... ... (date (2000,1,1), 0,0), ...])> gt; & Gt; & Gt; X array ([[2000-01-01, 0, 1], [2000-01-01, 1, 1], [2000-01-01, 1, 0], [2000-01-01, 0, 0 ]], Dtype = object)> gt; & Gt; & Gt; Y = np.rec.fromrecords (x)> & gt; & Gt; & Gt; Y Rick Array ([(datetime.date (2000, 1, 1), 0, 1), (datetime.date (2000, 1, 1), 1, 1), (datetime.date (2000, 1, 1), 1 , 0), (datetime.date (2000, 1, 1), 0, 0)], dtype = [('f0', '| O4'), ('f1', ' gt; & Gt; & Gt; X.ndim 2 & gt; & Gt; & Gt; Y.ndim 1 & gt; & Gt; & Gt; X Size (4, 3) & gt; & Gt; & Gt; Y.ndim 1 & gt; & Gt; & Gt; Y.shape (4,) & gt; & Gt; & Gt;
OK, this could be a more effective way, but this is a way :
(date (2000,1,1 ), 1,1), (date (2000,1,1), 1.0), (date (2000,1,1), 0,0),]) y = .rec.fromrecords for NP IDE ( X) z = np.empty ((len (y), lane (y.dtype)), dtype = 'object'), field enumerate (y.dtype.names): z [:, idx] = y [field] Assert (x == z) .all ()
Comments
Post a Comment