I am trying to do something simple, however I do not understand the resulting error. I have tried googling operands and broadcasting (python says thats what Im doing and Im doing it wrong), but that did not help me. I couldnt find an answer on SO either, but maybe Im using the wrong search terms.
I have a list of 64 sublists which have 64 entries. I want to create a new list of which each sublist has its entries moved to one side ( forward or backward, doesnt matter), then end clipped and the begin padded with zeros so it still has 64 entries. I thought I knew how to do this, but my solution does not work and I do not understand the error. It says I am broadcasting and that Im doing it wrong. However I just made some listcomprehensions (which are just for loops right?) and stuck them together.
Goal:
1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 0 1 2 3 4
1 2 3 4 5 becomes 0 0 1 2 3
1 2 3 4 5 0 0 0 1 2
1 2 3 4 5 0 0 0 0 1
My try:
result = [ [[0 for hh in range(ii)]+originallist[0][jj][0+ii:] for ii in range(64)] for jj in range(64)]
(the extra [0] behind originallist is there because the lists I describe above are actually sublists themselves of one motherlist, but in this example I only look at one such list)
Results in:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-51-5261c3ba129a> in <module>()
----> 1 result = [ [[0 for hh in range(ii)]+originallist[0][jj][0+ii:] for ii in range(64)] for jj in range(64)]
<ipython-input-51-5261c3ba129a> in <listcomp>(.0)
----> 1 result = [ [[0 for hh in range(ii)]+originallist[0][jj][0+ii:] for ii in range(64)] for jj in range(64)]
<ipython-input-51-5261c3ba129a> in <listcomp>(.0)
----> 1 result = [ [[0 for hh in range(ii)]+originallist[0][jj][0+ii:] for ii in range(64)] for jj in range(64)]
ValueError: operands could not be broadcast together with shapes (0) (64)