np.zeros((n - 1,))
时间: 2023-05-29 09:02:59 浏览: 162
This code creates a numpy array of zeros with n-1 elements. The shape of the array is (n-1, ). The dtype of the array is float64 by default.
For example, if n=5, then the code creates an array of shape (4,) with all elements set to 0.0:
```
import numpy as np
n = 5
arr = np.zeros((n - 1,))
print(arr)
Output:
[0. 0. 0. 0.]
```
相关问题
Y1定义为LABEL输出,Y1 = np.zeros((self.n - s, 1)), Y2是特征输出 :Y2 = np.zeros((self.n - s, self.m - 1))
好的,按照您的要求,修改后的函数如下所示:
```python
def _slice_multi(self):
# self.n 是数据集总行数
# self.m 是列
s = self.ps * self.skip + self.Ck - 1 + self.h - 1
X1 = np.zeros((self.n - s, self.w, self.m)) # 短期数据集
X2 = np.zeros((self.n - s, self.ps * self.Ck, self.m - 1)) # 长期数据集
Y1 = np.zeros((self.n - s, 1)) # LABEL输出
Y2 = np.zeros((self.n - s, self.m - 1)) # 特征输出
for i in range(s, self.n):
t = i - self.h + 1
X1[i - s] = self.raw[t - self.w:t].copy()
idx = []
for k in range(self.ps):
# 执行self.ps次,每次间隔self.skip长,取self.Ck=6, total = self.ps * self.Ck
idx = list(range(t - self.Ck - k * self.skip, t - k * self.skip)) + idx
idx = np.array(idx, dtype=int)
X2[i - s] = self.raw[idx, :-1].copy() # 去掉最后一列
Y1[i - s] = self.raw[i, -1].copy() # 最后一列为LABEL
Y2[i - s] = self.raw[i, :-1].copy() # 去掉最后一列
# 返回特征和标签
return (X1, X2), (Y1, Y2)
```
修改后的函数输出了两个元组,每个元组包含了两个数组,分别对应两个输出。其中Y1为LABEL输出,维度为 (n-s, 1),Y2为特征输出,维度为 (n-s, m-1)。
Y = np.zeros((self.n-s, self.m)) 不应改为 Y = np.zeros((self.n-s,predict_step ))吗?
如果要将`Y`数组的形状改为`(self.n-s, predict_step)`,那么代码应该修改为:
```
predict_step = 6
Y = np.zeros((self.n-s, predict_step))
...
Y[i-s] = self.raw[i : i+predict_step].copy()
```
这样的话,`Y`数组的形状就会正确地被定义为`(self.n-s, predict_step)`,其中`predict_step`表示需要预测的时间步数,其值为6。
阅读全文