python - How to omit some values in an array -
this question has answer here:
i have vector vec-it's length 1774. , need make vector n of length 10 contain 10 numbers of vec similar step like:
n=[0, 178, 356, 534, 712, 890, 1068, 1246, 1424, 1602]
first , last numbers not have same in vec. try:
# -*- coding: cp1250 -*- __future__ import division newlength=10 vec=range(1774) step=round(len(vec)/newlength); n=range(0,len(vec),int(step)) print n print len(n)
but results vector of length 11. when set newlength=22 22. problem of rounding (i tried math.ceil , math.floor-it works newlength=10 not newlength=554). there other way how vector n?
thanks
think this:
- you have 1774 apples.
- you want split apples 554 equally sized groups.
- the group size must 1774/554 = 3.261.
- you round group size down , 3.
- you 1774//3 = 591 groups.
- you see wrong.
- you decide round instead , 4.
- you 1774//4 = 443 groups.
- you see wrong well.
- you realise must able have .261 of apple.
- you write code facilitate this.
- you decide have party because have 1774//3.261 = 544 groups!
the code:
new_length = 554 vector = # list step = len(vector)/new_length n = (i*step in range(new_length)) new_vector = [vector[int(round(i))] in n]
Comments
Post a Comment