Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Error
#1
Could somebody please tell me why the variable 'collapse_steps' is not returned in the variable 'collapse_times'?

collapse_duration = 60.0 
collapse_steps = 2  # can be changed by USER
collapse_starttime = 0.0  # in second; can be changed by USER
collapse_times = np.linspace(0,collapse_duration,collapse_steps)
print(collapse_duration)
print(collapse_steps)
print(collapse_times)
Error:
60.0 2 [ 0. 60.]
Reply
#2
What error? Do you think collapse_times should have 3 numbers? In linspace(0, collapse_duration, collapse_steps), 0 is the start value, collapse_duration the end value, and collapse steps the number of values in the returned samples array.
import numpy as np
for i in range(1, 6):
  print(i, np.linspace(0, 100, i))
Output:
1 [0.] 2 [ 0. 100.] 3 [ 0. 50. 100.] 4 [ 0. 33.33333333 66.66666667 100. ] 5 [ 0. 25. 50. 75. 100.]
Or were you expecting linspace to return the step size. For that you need to set retstep to True.
import numpy as np
print(np.linspace(0, 100, 5, retstep=True))
Output:
(array([ 0., 25., 50., 75., 100.]), 25.0)
More information about numpy.linspace is here:

https://numpy.org/doc/stable/reference/g...space.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error with print and return commands TheDark_Knight 2 1,944 Jan-15-2020, 04:59 PM
Last Post: TheDark_Knight
  I am getting an Error, and not sure why? My goal is to print out rahulne22 7 3,078 Dec-01-2019, 03:53 PM
Last Post: snippsat
  Error in print statment leodavinci1990 1 1,941 Jul-21-2019, 04:46 AM
Last Post: buran
  Why do i have invalid syntax on a line after print, i see no error ? iofhua 5 2,943 May-24-2019, 05:42 PM
Last Post: Yoriz
  Need help with print error newbiepy 2 2,103 Apr-22-2019, 08:00 PM
Last Post: Yoriz
  Attribute error print statement error jamshaid1997 1 2,472 Jan-20-2019, 04:02 PM
Last Post: ichabod801
  Only one of two lines print/syntax error naysjp 2 3,746 Jan-12-2017, 07:08 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020