运行后
import numpy as np
randn = np.random.randn
from pandas import *
以下代码创建了一个面板:
## 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 for each indiv: N(2,1)
wp.ix[:,:,'background'] = np.tile(randn(numindivs)+2,(numwaves,1))
# Generate lnF and lnT
wp.ix[:,:,'lnF'] = np.log(wp[:,:,'F']+1)
wp.ix[:,:,'lnT'] = np.log(wp[:,:,'T']+1)
然而,以下代码除了更改倒数第二部分中“背景”列的内容外,都是相同的,会产生错误(“ValueError:无法将形状(2)中的输入数组广播为形状(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 and lnT
wp.ix[:,:,'lnF'] = np.log(wp[:,:,'F']+1)
wp.ix[:,:,'lnT'] = np.log(wp[:,:,'T']+1)
这是非常奇怪的行为。有人可以解释发生了什么吗?
谢谢!
答案 0 :(得分:0)