Simplify identity initializer with zero padding
@@ -283,20 +283,7 @@ class Identity(Initializer):
raise ValueError(
'Identity matrix initializer can only be used for 2D matrices.')
- if shape[0] == shape[1]:
- return self.gain * np.identity(shape[0])
- elif shape[0] > shape[1]:
- return self.gain * np.concatenate(
- [np.identity(shape[1]),
- np.zeros((shape[0] - shape[1], shape[1]))],
- axis=0
- )
- else:
- return self.gain * np.concatenate(
- [np.identity(shape[0]),
- np.zeros((shape[0], shape[1] - shape[0]))],
- axis=1
- )
+ return self.gain * np.eye(shape[0], shape[1])
def get_config(self):
return {
