#NEWLINE# def expand_dims( x , dim = ( - 1 ) ) : #NEWLINE# #INDENT# 'Add a 1-sized dimension at index "dim".\n    ' #NEWLINE# pattern = [ i for i in range ( x . type . ndim ) ] #NEWLINE# if ( dim < 0 ) : #NEWLINE# #INDENT# if ( x . type . ndim == 0 ) : #NEWLINE# #INDENT# dim = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dim = ( ( dim % x . type . ndim ) + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# pattern . insert ( dim , 'x' ) #NEWLINE# return x . dimshuffle ( pattern )