我有一个文件,其中包含以下格式的数据:
I have a file containing data in the format:
0.0 x1 0.1 x2 0.2 x3 0.0 x4 0.1 x5 0.2 x6 0.3 x7 ...数据由多个数据集组成,每个数据集的第一列均以0开头(因此x1,x2,x3是一个集合,x4,x5,x6,x7是另一个集合).我需要分别绘制每个数据集,所以我需要以某种方式拆分数据.最简单的方法是什么?
The data consists of multiple datasets, each starting with 0 in the first column (so x1,x2,x3 would be one set and x4,x5,x6,x7 another one). I need to plot each dataset separately so I need to somehow split the data. What would be the easiest way to accomplish this?
我意识到我可以逐行浏览数据并在第一列中遇到0时拆分数据,但这似乎效率很低.
I realize I could go through the data line-by-line and split the data every time I encounter a 0 in the first column but this seems very inefficient.
推荐答案我实际上很喜欢本杰明的答案,一个简短的解决方案是:
I actually liked Benjamin's answer, a slightly shorter solution would be:
B= np.split(A, np.where(A[:, 0]== 0.)[0][1:])更多推荐
以numpy中的值拆分数组
发布评论