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:

  1. you have 1774 apples.
  2. you want split apples 554 equally sized groups.
  3. the group size must 1774/554 = 3.261.
  4. you round group size down , 3.
  5. you 1774//3 = 591 groups.
  6. you see wrong.
  7. you decide round instead , 4.
  8. you 1774//4 = 443 groups.
  9. you see wrong well.
  10. you realise must able have .261 of apple.
  11. you write code facilitate this.
  12. 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

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -