python - Baffling panda panel behavior -


after running

import numpy np  randn = np.random.randn pandas import * 

the following code creates panel:

## create pseudo panel data ## numindivs = 2 # number of individuals numwaves = 5 # number of time periods (waves)  # create panel object wp = panel(np.random.randint(12, size=(numindivs, numwaves, 4)), minor_axis=['background', 'lnh', 'f', 't'])  # generate random fixed background variable each indiv: n(2,1) wp.ix[:,:,'background'] = np.tile(randn(numindivs)+2,(numwaves,1))  # generate lnf , lnt wp.ix[:,:,'lnf'] = np.log(wp[:,:,'f']+1) wp.ix[:,:,'lnt'] = np.log(wp[:,:,'t']+1) 

yet, following code, identical except changing contents of 'background' column in penultimate section, generates error ("valueerror: not broadcast input array shape (2) shape (5)"):

## create pseudo panel data ## numindivs = 2 # number of individuals numwaves = 5 # number of time periods (waves)  # create panel object wp = panel(np.random.randint(12, size=(numindivs, numwaves, 4)), minor_axis=['background', 'lnh', 'f', 't'])  # generate lnf , lnt wp.ix[:,:,'lnf'] = np.log(wp[:,:,'f']+1) wp.ix[:,:,'lnt'] = np.log(wp[:,:,'t']+1) 

this extremely odd behavior. can explain going on?

thanks!

that bit strange, has how dtypes getting coerced when assign. can report issue here.

it seems direct assignment works without issue though:

 wp['lnf'] = np.log(wp[:,:,'f']+1) 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -