[英]Why is this Python array not slicing?
Initial data is:初始数据为:
array([[0.0417634 ],
[0.04493844],
[0.04932728],
[0.04601787],
[0.04511007],
[0.04312284],
[0.0451733 ],
[0.04560687],
[0.04263394],
[0.04183227],
[0.048634 ],
[0.05198746],
[0.05615724],
[0.05787913], dtype=float32)
then i transformed it in 2d array然后我将它转换为二维数组
array2d = np.reshape(dataset, (-1, 2))
now i have我现在有
array([[0.0417634 , 0.04493844],
[0.04932728, 0.04601787],
[0.04511007, 0.04312284],
[0.0451733 , 0.04560687],
[0.04263394, 0.04183227],
[0.048634 , 0.05198746],
[0.05615724, 0.05787913],
[0.05989346, 0.0605077 ], dtype=float32)
Now i'm going to calcolulate the mean between each element of the array现在我要计算数组的每个元素之间的平均值
paa = []
paa.append(array2d.mean(axis=1))
now i want a list of intervals from this list现在我想要这个列表中的间隔列表
intervals = paa[::10]
intervals
but the result is the same list (paa).但结果是相同的列表(paa)。 Why?为什么? Already tried to convert it in np.array(paa)已经尝试在 np.array(paa) 中转换它
Expected a new list with less elements.期望元素较少的新列表。 Since 10 is the nr of steps i'm expecting [0.0417634, ... paa[11], .... paa[21] .... ]由于 10 是我期望的步数 [0.0417634, ... paa[11], .... paa[21] .... ]
np.mean
will return a np.array
. np.mean
将返回一个np.array
。 You are taking the result and appending it into a list
.您正在获取结果并将其附加到list
。 When you are slicing it, you're getting the 0th
(and only) element in paa
, which is an entire np.array
.切片时,您将获得paa
的0th
(也是唯一的)元素,它是整个np.array
。
Get rid of the list
and append and slice directly into the result of mean.摆脱list
并直接追加和切片到均值的结果中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.