Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make the time from len of array

How to make time from len of array…

Picture 1:
enter image description here

Picture 2:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How to make the picture 1 as picture 2

Picture 1 come from below:

`

x=[]
colors=['red','green','brown','teal','gray','black','maroon','orange','purple']
colors2=['green','red','orange','black','maroon','teal','blue','gray','brown']
for i in range(0,1950):
    x.append(i)
for i in range(0,1):
    plt.figure(figsize=(15,6))
    # plt.figure()
    plt.plot(x,out[0:1950,i],color=colors[i])
    plt.plot(x,predictions[0:1950,i],markerfacecolor='none',color=colors2[i])
    plt.title('LSTM Regression (Training Data)')
    plt.ylabel('Force/Fz (N)')
    plt.xlabel('Time/s')
    plt.legend(['Real value', 'Predicted Value'], loc='upper right')
    plt.savefig('Regression Result.png'[i])
    plt.show()

`

>Solution :

@ahrensaj’s answer makes sense.

Here is your code modified to rescale the time scale.

x=[]
colors=['red','green','brown','teal','gray','black','maroon','orange','purple']
colors2=['green','red','orange','black','maroon','teal','blue','gray','brown']
# just update the x with correct scaling; use numpy array for faster computations
x = numpy.arange(0,1950)*40/1950 
for i in range(0,1):
    plt.figure(figsize=(15,6))
    # plt.figure()
    plt.plot(x,out[0:1950,i],color=colors[i])
    plt.plot(x,predictions[0:1950,i],markerfacecolor='none',color=colors2[i])
    plt.title('LSTM Regression (Training Data)')
    plt.ylabel('Force/Fz (N)')
    plt.xlabel('Time/s')
    plt.legend(['Real value', 'Predicted Value'], loc='upper right')
    plt.savefig('Regression Result.png'[i])
    plt.show()

EDIT:
@minn’s comment made me curious about np.linspace vs np.arange. I often use np.arange and divide appropriately because it is one less command to remember. In any case, I benchmarked the two. np.arange seems to do better.

In [8]: %time [np.linspace(0,40,1950) for _ in range(10)]
CPU times: user 1.81 ms, sys: 146 µs, total: 1.96 ms
Wall time: 1.6 ms
In [9]: %time [np.arange(0,1950)/40 for _ in range(10)]
CPU times: user 794 µs, sys: 55 µs, total: 849 µs
Wall time: 1.09 ms
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading