def unit_impulse(shape, idx=None, dtype=float):
 out = zeros(shape, dtype)
 shape = np.atleast_1d(shape)
 if (idx is None):
  idx = ((0,) * len(shape))
 elif (idx == 'mid'):
  idx = tuple((shape // 2))
 elif (not hasattr(idx, '__iter__')):
  idx = ((idx,) * len(shape))
 out[idx] = 1
 return out

def unit_impulse ( shape , idx = None , dtype = float ) : out = zeros ( shape , dtype ) shape = np . atleast_1d ( shape ) if ( idx is None ) : idx = ( ( 0 , ) * len ( shape ) ) elif ( idx == 'mid' ) : idx = tuple ( ( shape // 2 ) ) elif ( not hasattr ( idx , '__iter__' ) ) : idx = ( ( idx , ) * len ( shape ) ) out [ idx ] = 1 return out
unit impulse signal or unit basis vector .