in sparse_tools.py [0:0]
def pad_with_zeros(A, n, side="bottom"):
"""Pad the bottom of a matrix with n rows of zeros"""
if sparse.issparse(A):
if side == "top":
return sparse.vstack([sparse.csr_matrix((n, A.shape[1])), A])
elif side == "bottom":
return sparse.vstack([A, sparse.csr_matrix((n, A.shape[1]))])
elif side == "left":
return sparse.hstack([sparse.csr_matrix((A.shape[0], n)), A])
elif side == "right":
return sparse.hstack([A, sparse.csr_matrix((A.shape[0], n))])
else:
if A.ndim == 1:
return np.pad(A, (0, n), mode="constant")
else:
if side == "top":
return np.pad(A, [(n, 0), (0, 0)], mode="constant")
elif side == "bottom":
return np.pad(A, [(0, n), (0, 0)], mode="constant")
elif side == "left":
return np.pad(A, [(0, 0), (n, 0)], mode="constant")
elif side == "right":
return np.pad(A, [(0, 0), (0, n)], mode="constant")