简体   繁体   English

根据先前获得最高值的数组创建新数组

[英]Creating new array based off previous array getting top values

I have an array in Jupyter.我在 Jupyter 中有一个数组。 I want to create two new arrays, one with the top 30% of values from the original array and one with the bottom 30% of values from the original array.我想创建两个新的 arrays,一个包含原始数组中前 30% 的值,一个包含原始数组中后 30% 的值。 Please help!请帮忙!

In Python you do it like this:在 Python 你这样做:

X = [1,2,3,4,5,6,7,8,9,10]
len_pct = int(len(X) * 0.3)

first, last = X[0:len_pct], X[len(X)-len_pct:len(X)]

print(first); # [1,2,3]
print(last); # [8,9,10]

Live demo here现场演示在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM