Python Forum
Array input with time module (Python 3)
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array input with time module (Python 3)
#1
Hello,

I have to generate a graphic from a .dat file in which the 2nd columns (which will be the x axis) is filled with different times of format HH:MM. The intervals between each time vary a lot (from 1 min to 7 min) and absolutely randomly.

I have tried :
import numpy as np
import matplotlib.pyplot as plt
import time

signal = np.genfromtxt('path\file.DAT')
Time = signal[:,1]
t = time.strptime(Time,'%I:%M')
y = signal[:,2]
plt.plot(t,y)
plt.show()
Running the program I get the following error message :
Error:
Traceback (most recent call last):

Sorry for the short ending,I made a typing error and for a reason I cannot repaste the full Error message at once and it is really long (it took me more than ten minutes to write it all down befoere editing and then I lost it all because the editing time had passed)...

At the end I get :
Error:
TypeError: strptime() argument 0 must be str, not <class 'numpy.ndarray'
Reply
#2
You could try parsing the data in the .DAT file into a string before you create Time. Essentially, the argument your passing 'Time' is not what strptime() is expecting. Check the type of 'signal' and the type of 'Time' so you know what your dealing with:

print(type(signal), type(Time))
Reply
#3
Thank you a lot for the advice. They are both numpy.ndarray... Can you help me in "parsing the data into a string" please? (I am really bad with vocabulary and found so many different things on the internet forums I am completely lost)
Reply
#4
I have never used numpy before but a quick google search says there exists a function called: array_str() which converts a numpy array into a string: https://docs.scipy.org/doc/numpy-1.14.0/...y_str.html
Reply
#5
OK, thank you a lot (for the link and all)! I'll try right away and see what comes of it! =)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 45,278 May-29-2019, 02:48 AM
Last Post: heiner55
  How to use pandas.rolling mean for 3D input array? Prv_Yadv 1 3,811 Mar-26-2019, 11:49 AM
Last Post: scidam
  ValueError: could not broadcast input array from shape (75) into shape (25) route2sabya 0 6,445 Mar-14-2019, 01:14 PM
Last Post: route2sabya
  Help to arrange correct input array structure mogensen24 1 2,359 Oct-05-2018, 06:09 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

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