Bottom Page

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

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]
Running the program I get the following error message :
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 :
TypeError: strptime() argument 0 must be str, not <class 'numpy.ndarray'
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))
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)
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:
OK, thank you a lot (for the link and all)! I'll try right away and see what comes of it! =)

Top Page

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

Forum Jump:

Users browsing this thread: 1 Guest(s)