Lucas Gorski Lucas Gorski - 4 months ago 64
Python Question

only length-1 arrays can be converted to Python scalars When using matlab keys

I'm trying to convert serial date number data in a matlab file to UTC using python.

from datetime import *
import scipy.io as sio
import toutc as toutc
from numpy import *
from plotting import *
import matplotlib.pyplot as plt
S = sio.loadmat(*MatLab_File.mat*)
print (S.keys()) # Time is stored as the key 't'
from datetime import datetime, timedelta
SDN = S[str(input('time'))] # Establishing we are using the key 't'
X = (datetime.fromordinal[SDN] + timedelta(days=SDN%1) - timedelta(days = 366))


This last line returns

Traceback (most recent call last):
File "matgraph.py", line 19, in <module>
X = (datetime.fromordinal(SDN) + timedelta(days=SDN%1) - timedelta(days = >366))
TypeError: only length-1 arrays can be converted to Python scalars


Any idea why this isn't working?

Thank you

Edit: changed '[]' to '()' on last line and updated error to match

Answer

You have fromordinal[SDN] instead of fromordinal(SDN).

Comments