csv - Python: Numpy, the data genfromtxt cannot do tranpose -
for example, if have data.csv file, looks like:
b 1| 1 2 2| 3 4 if load info way:
import numpy np stringio import stringio open('test.csv', 'rb') text: b = np.genfromtxt( stringio(text.read()), delimiter=",", dtype = [('x', int), ('y', int)]) ##<=== in case ## want may columns dtype ## in different format print b.tranpose() it still gives me this, not been transposed.
[(1,2) (3,4)] but if do: dtype = 'str' (which means columns same format np.transpose() works good.
===============================================
but if way like:
import numpy np = np.array([(1,2), (3,4)]) print a.transpose() it works correctly
======= question ======= if load numpy info txt or csv, , define each columns' info type. there way create numpy info working properly?
this designed do, see document
t same self.transpose(), except self returned if self.ndim < 2.
here have ndim of 1 b array (you may think has shape of (2,2) has shape of (2,), aware), t returns itself.
python csv numpy
No comments:
Post a Comment