python - Why does numpy.concatenate work along axis=1 for small one dimensional arrays, but not larger ones? -
i couldn't 4 arrays of year, day of year, hour, , minute concatenate way wanted, decided test several variations on shorter arrays data.
i found worked using method "t" test code:
import numpy np a=np.array([[1, 2, 3, 4, 5, 6]]) b=np.array([[11, 12, 13, 14, 15, 16]]) c=np.array([[21, 22, 23, 24, 25, 26]]) d=np.array([[31, 32, 33, 34, 35, 36]]) print print b print c print d q=np.concatenate((a, b, c, d), axis=0) #concatenation along 1st axis print q t=np.concatenate((a.t, b.t, c.t, d.t), axis=1) #transpose each array before concatenation along 2nd axis print t x=np.concatenate((a, b, c, d), axis=1) #concatenation along 2nd axis print x
but when tried larger arrays behaved same method "q".
i found alternative approach of using vstack over here did wanted, trying figure out why concatenation works this, not always.
thanks insights.
also, here outputs of code:
q:
[[ 1 2 3 4 5 6] [11 12 13 14 15 16] [21 22 23 24 25 26] [31 32 33 34 35 36]]
t:
[[ 1 11 21 31] [ 2 12 22 32] [ 3 13 23 33] [ 4 14 24 34] [ 5 15 25 35] [ 6 16 26 36]]
x:
[[ 1 2 3 4 5 6 11 12 13 14 15 16 21 22 23 24 25 26 31 32 33 34 35 36]]
edit: added method t end of section of code fixed vstack, can compare how vstack work data not concatenate. again, clarify, found workaround already, don't know why concatenate method doesn't seem consistent.
here code:
import numpy np bao10m=np.genfromtxt('bao_010_2015176.dat', delimiter=",", usecols=range(0-6), dtype=[('h', int), ('year', int), ('day', int), ('time', int), ('temp', float)]) #10 meter weather readings @ bao tower site june 25, 2015 hourbao=bao10m['time']/100 minutebao=bao10m['time']%100 #print hourbao #print minutebao #time arrays daybao=bao10m['day'] yearbao=bao10m['year'] #date arrays datetimebao=np.vstack((yearbao, daybao, hourbao, minutebao)) #t=np.concatenate((a.t, b.t, c.t, d.t), axis=1) <this gave desired results in simple tests #not working data, use vstack instead, transposition after stack print datetimebao test=np.transpose(datetimebao) #rotate array print test #this prints can used datetime t=np.concatenate((yearbao.t, daybao.t, hourbao.t, minutebao.t), axis=1) print t #this prints 1d array of year values, day values, etc... #but method worked shorter 1d arrays
the file used can found @ this site.
Comments
Post a Comment