def stride_repeat(x, n, axis=0):
 if (axis not in [0, 1]):
  raise ValueError(u'axis must be 0 or 1')
 x = np.asarray(x)
 if (x.ndim != 1):
  raise ValueError(u'only 1-dimensional arrays can be used')
 if (n == 1):
  if (axis == 0):
   return np.atleast_2d(x)
  else:
   return np.atleast_2d(x).T
 if (n < 1):
  raise ValueError(u'n cannot be less than 1')
 n = int(n)
 if (axis == 0):
  shape = (n, x.size)
  strides = (0, x.strides[0])
 else:
  shape = (x.size, n)
  strides = (x.strides[0], 0)
 return np.lib.stride_tricks.as_strided(x, shape=shape, strides=strides)

def stride_repeat ( x , n , axis = 0 ) : if ( axis not in [ 0 , 1 ] ) : raise ValueError ( u'axis must be 0 or 1' ) x = np . asarray ( x ) if ( x . ndim != 1 ) : raise ValueError ( u'only 1-dimensional arrays can be used' ) if ( n == 1 ) : if ( axis == 0 ) : return np . atleast_2d ( x ) else : return np . atleast_2d ( x ) . T if ( n < 1 ) : raise ValueError ( u'n cannot be less than 1' ) n = int ( n ) if ( axis == 0 ) : shape = ( n , x . size ) strides = ( 0 , x . strides [ 0 ] ) else : shape = ( x . size , n ) strides = ( x . strides [ 0 ] , 0 ) return np . lib . stride_tricks . as_strided ( x , shape = shape , strides = strides )
repeat the values in an array in a memory-efficient manner .