0

I'm trying to write to numPy matrix a date in numpy.datetime64.

The command:

date_vec[row][ind] = np.datetime64(row[date_ind][ind], dtype='datetime64')

Returns:

TypeError: "Cannot cast NumPy timedelta64 scalar from metadata [us] to  according to the rule 'same_kind'"

The np.datetime64(row[date_ind][ind], dtype='datetime64') returns:

numpy.datetime64('2004-10-19T10:23:54.000000+0200')

What am I missing?

Michał
  • 2,456
  • 4
  • 26
  • 33
user2495766
  • 123
  • 3
  • 15
  • What are `date_vec[row][ind]` and `row[date_ind][ind]`? – Kei Minagawa Mar 09 '14 at 14:12
  • The date_vec[row][ind] defined by: date_vec[row][ind] = np.empty((MAX_SAMPLES, NUM), dtype=datetime64) Both MAX_SAMPLES, NUM are int.. The row[date_ind][ind] is datetime.datetime (Pdb) p row[date_ind][ind] datetime.datetime(2004, 10, 19, 8, 23, 54, tzinfo=) – user2495766 Mar 09 '14 at 14:55
  • I don't know. But can you post more code? I will try your code and see if it raises error. – Kei Minagawa Mar 10 '14 at 12:15

1 Answers1

0

Thanks for any whom try to help me :) I've just found this explanation The short solution was different instantiate of the array:

date_vec = zeros((MAX_A,NUM_OF_B),dtype=[('i',np.int),('date','datetime64[D]')]) 
Community
  • 1
  • 1
user2495766
  • 123
  • 3
  • 15