def unpad(matrix):
'''
Strip off a column (e.g. of ones). Transform from:
array([[1., 2., 3., 1.],
[2., 3., 4., 1.],
[5., 6., 7., 1.]])
to:
array([[1., 2., 3.],
[2., 3., 4.],
[5., 6., 7.]])
'''
if matrix.ndim != 2 or matrix.shape[1] != 4:
raise ValueError("Invalid shape %s: unpad expects nx4" % (matrix.shape,))
if not all(matrix[:, 3] == 1.):
raise ValueError('Expected a column of ones')
return np.delete(matrix, 3, axis=1)
评论列表
文章目录