I have three arrays of the same length containing integers: years, months and days. I want to create a (NumPy) array of the same length, containing formatted strings like '(-)yyyy-mm-dd' using the format '%i-%2.2i-%2.2i'.
For the scalar case, I would do something like
year=2000; month=1; day=1
datestr = '%i-%2.2i-%2.2i' % (year, month, day)
which would yield '2000-01-01'.
How can I create the vector version of this, e.g.:
import numpy as np
years = np.array([-1000, 0, 1000, 2000])
months = np.array([1, 2, 3, 5])
days = np.array([1, 11, 21, 31])
datestr_array = numpy.somefunction(years, months, days, format='%i-%2.2i-%2.2i', ???)
Note that the date range I am interested in lies between the years -2000 and +3000 (CE), and hence both Python's datetime and Pandas' DateTimeIndex offer no solution.
datastr_array = ['%i-%2.2i-%2.2i'.format(years[j], months[j], days[j]) for j in range(len(years))]- while this may look complicated, it is literally just formatting however many times are necessary.