I know this has been asked dozens of times, and I've tried to get the intuition (here, here) of working with multi-dimensional arrays but I can't figure out the process.
I am getting days, weeks, months of the year using yeardatescalendar()
from the Calendar library, packed into a 4D list.
import calendar
cal = calendar.Calendar()
yr_11 = cal.yeardatescalendar(2011)
The return value is a list of month rows. Each month row contains up to 3 months. Each month contains between 4 and 6 weeks and each week contains 1–7 days.
I am trying to convert this to a 2D array so it is just a list of weeks. But even when I'm trying to do this I don't understand the output.
# create an array
arr = np.array(yr_11)
arr.ndim # this returns '2'
arr.shape # this returns (4,3)
# yr_11 holds 63 weeks, so I tried to reshape
new_array = arr.reshape(63,1)
But it throws an error: ValueError: cannot reshape array of size 12 into shape (63,1)
Can someone please explain what's going on and help turn this into a 2D array?
Edit: essentially I'm looking for this
[[datetime.date(2010, 12, 27),
datetime.date(2010, 12, 28),
datetime.date(2010, 12, 29),
datetime.date(2010, 12, 30),
datetime.date(2010, 12, 31),
datetime.date(2011, 1, 1),
datetime.date(2011, 1, 2)],
[datetime.date(2011, 1, 3),
datetime.date(2011, 1, 4),
datetime.date(2011, 1, 5),
datetime.date(2011, 1, 6),
datetime.date(2011, 1, 7),
datetime.date(2011, 1, 8),
datetime.date(2011, 1, 9)], ... ]