0

I want to give paramters valueFrom, valueTo and length.out. The same how seq function works in R:

seq(0, 1, length.out = 5) 

0.00 0.25 0.50 0.75 1.00

How to do it in python?

Is the only solution is:

range(valueFrom, valueTo, by=(valueTo - ValueFrom)/(lengthOut - valueTo - ValueFrom)) ?

Python is really messy language in compare with R or Java.

stakowerflol
  • 979
  • 1
  • 11
  • 20
  • see np.linspace() in numpy module – taurus05 Jan 31 '19 at 08:55
  • 5
    "Python is really messy language in compare with R or Java" - I think otherwise my good sir – Jab Jan 31 '19 at 08:56
  • 1
    Indeed @Jaba, same – yatu Jan 31 '19 at 08:57
  • 1
    Although the only error in my comment is I am assuming OP's gender. *(hope I'm right)* – Jab Jan 31 '19 at 08:58
  • In python even I can't use letters like `ć` in comments !!! ERROR `SyntaxError: Non-UTF-8 code starting with '\xe6'`. Python is really awkward. – stakowerflol Jan 31 '19 at 09:05
  • @stakowerflol it's usually frowned upon to comment code in any other language than English – ruohola Jan 31 '19 at 09:15
  • @stakowerflol you absolutely can. What editor are you using? What encoding is the source file saved in? See the first two paragraphs in [this answer](https://stackoverflow.com/a/23092402/4570170). – Chillie Jan 31 '19 at 09:18

2 Answers2

2

In python you can use np.arange for this:

import numpy as np
np.arange(0,1.25,0.25)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])

Or if you want to create a sequence by specifying its length use np.linspace:

np.linspace(0,1,5)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
yatu
  • 86,083
  • 12
  • 84
  • 139
2

Use NumPy module, it has many useful functions

import numpy as np
print(np.linspace(0, 1, 5))
taurus05
  • 2,491
  • 15
  • 28
Mikhail Efimov
  • 343
  • 1
  • 7