numpy API: np.repeat

np.repeat(a, repeats, axis=None)
作用:
复制数组的元素。

Parameters

a : array_like
Input array.
repeats : int or array of ints
每个元素复制多少次.
axis : 默认会先flattened输入数组,返回flat的输出数组。

Returns

repeated_array : ndarray
Output array which has the same shape as a, except along
the given axis.

See Also

tile : Tile an array.


例子:

>>> np.repeat(3, 4) #默认扁平化
array([3, 3, 3, 3])
>>> x = np.array([[1,2],[3,4]])
>>> np.repeat(x, 2)#没有axis参数输出被扁平化
array([1, 1, 2, 2, 3, 3, 4, 4])
>>>np.repeat(x, 2,axis=1)#1轴上进行复制,每个复制两次
array([[1, 1, 2, 2],
       [3, 3, 4, 4]])
>>> np.repeat(x, 2,axis=0)
   array([[1, 2],
       [1, 2],
       [3, 4],
       [3, 4]])   
np.repeat(x, [1, 2], axis=0)#沿着0轴第一个元素复制一次,第二个元素复制两次
array([[1, 2],
       [3, 4],
       [3, 4]])
X2=[] X3=[] X4=[] X5=[] X6=[] X7=[] X1=[i for i in range(1,24) for j in range(128)] X1=X1[:2928] df=pd.read_excel('C:/Users/86147/OneDrive/文档/777.xlsx',header=0,usecols=(3,)) X2=df.values.tolist() x2=[] x21=[] for i in X2: if X2.index(i)<=2927: x2.append(i) else: x21.append(i) # x2=x2[:len(x21)] df=pd.read_excel('C:/Users/86147/OneDrive/文档/777.xlsx',header=0,usecols=(4,)) X3=df.values.tolist() x3=[] x31=[] for i in X3: if X3.index(i)<=2927: x3.append(i) else: x31.append(i) # x3=x3[:len(x31)] df=pd.read_excel('C:/Users/86147/OneDrive/文档/777.xlsx',header=0,usecols=(5,)) X4=df.values.tolist() x4=[] x41=[] for i in X4: if X4.index(i)<=2927: x4.append(i) else: x41.append(i) # x4=x4[:len(x41)] df=pd.read_excel('C:/Users/86147/OneDrive/文档/777.xlsx',header=0,usecols=(6,)) X5=df.values.tolist() x5=[] x51=[] for i in X5: if X5.index(i)<=2927: x5.append(i) else: x51.append(i) # x5=x5[:len(x51)] df=pd.read_excel('C:/Users/86147/OneDrive/文档/777.xlsx',header=0,usecols=(7,)) X6=df.values.tolist() x6=[] x61=[] for i in X6: if X6.index(i)<=2927: x6.append(i) else: x61.append(i) # x6=x6[:len(x61)] df=pd.read_excel('C:/Users/86147/OneDrive/文档/777.xlsx',header=0,usecols=(8,)) X7=df.values.tolist() x7=[] x71=[] for i in X7: if X7.index(i)<=2927: x7.append(i) else: x71.append(i) # x7=x7[:len(x71)]np.random.seed(42) q=np.array(X1) w=np.array(x2) e=np.array(x3) r=np.array(x4) t=np.array(x5) p=np.array(x6) u=np.array(x7) eps=np.random.normal(0,0.05,152) X=np.c_[q,w,e,r,t,p,u] beta=[0.1,0.15,0.2,0.5,0.33,0.45,0.6] y=np.dot(X,beta) X_model=sm.add_constant(X) model=sm.OLS(y,X_model) results=model.fit() print(results.summary())具体代码如下,要怎么修改?
06-01
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值