0

I am using PySpice for circuit simulation in Python and find it puzzling that the slice() function is used in this context with a fractional value for step size. For example, the following line of code from docs sweeps over an input voltage from -2 volts to 5 volts in increments of 0.01 volts.

analysis = simulator.dc(Vinput=slice(-2, 5, .01))

Looking up slice() in Python, docs state that the step is integer-valued.

Step: (Optional) An integer that specifies the step of the slicing process.

Wouldn't it be more natural to use a numpy array created with np.arange(-2, 5, 0.01) in place of slice? The method simulator.dc() however only accepts slice as shown.

What gives?

Sun Bee
  • 1,595
  • 15
  • 22
  • 1
    I'm sorry, it isn't clear what you are asking. A very obvious downside to using `np.arange` is that creates an *entire array*, a slice is constant space. – juanpa.arrivillaga Dec 09 '21 at 21:36
  • As an aside, nowhere do you link to the python docs. You link to some random website. Here are [the actual `docs` for the `slice` class](https://docs.python.org/3/library/functions.html#slice). It says nothing about integers. My advice, use the actual Python documentation, not random websites – juanpa.arrivillaga Dec 09 '21 at 21:38
  • 1
    Note, slice objects exist as the corresponding concrete type of the following syntactic sugar: `some_object[start:stop:step]`, this essentially calls `type(some_object).__getitem__(slice(start, stop, step))`. It is up to `type(some_object)` to implement the semantics – juanpa.arrivillaga Dec 09 '21 at 21:39
  • Got it, thanks. :) – Sun Bee Dec 09 '21 at 21:51

0 Answers0