zero-pad

Forming a frame of zeros around a matrix in python

Forming a frame of zeros around a matrix in python Question: I am trying to pad a matrix with zeros, but am not really sure how to do it. Basically I need to surround a matrix with an n amount of zeros. The input matrix is huge (it represents an image) Example: Input: 1 2 …

Total answers: 1

Zero pad numpy array

Zero pad numpy array Question: What’s the more pythonic way to pad an array with zeros at the end? def pad(A, length): … A = np.array([1,2,3,4,5]) pad(A, 8) # expected : [1,2,3,4,5,0,0,0] In my real use case, in fact I want to pad an array to the closest multiple of 1024. Ex: 1342 => 2048, …

Total answers: 6

Python datetime formatting without zero-padding

Python datetime formatting without zero-padding Question: Is there a format for printing Python datetimes that won’t use zero-padding on dates and times? Format I’m using now: mydatetime.strftime(‘%m/%d/%Y %I:%M%p’) Result: 02/29/2012 05:03PM Desired: 2/29/2012 5:03PM What format would represent the month as ‘2’ instead of ’02’, and time as ‘5:03PM’ instead of ’05:03PM’ Asked By: Yarin …

Total answers: 9