#NEWLINE# def tile_tens3d( T , width = None ) : #NEWLINE# #INDENT# '\n  Tile the slabs of a 3D tensor T.\n\n  Useful for visualization of stacks of arrays and 3D tensors.\n\n  Parameters\n  ----------\n  T : 3D array\n    The tensor to be tiled. The first dimension is rearranged, the 2D\n    relation of the latter two are preserved.\n  width : int, optional\n    Determines how many 2D slabs are tiled horizontally. Tiling\n    continues on the row below.\n\n  Returns\n  -------\n  out : 2D array\n    The tiled version of `T`. If `T` cannot completely cover `out`,\n    the empty regions are filled with NaNs.\n\n  Examples\n  --------\n  >>> tile_tens3d(np.zeros((5, 2, 3)) + np.arange(5).reshape(-1, 1, 1))\n  array([[  0.,   0.,   0.,   1.,   1.,   1.,   2.,   2.,   2.],\n         [  0.,   0.,   0.,   1.,   1.,   1.,   2.,   2.,   2.],\n         [  3.,   3.,   3.,   4.,   4.,   4.,  nan,  nan,  nan],\n         [  3.,   3.,   3.,   4.,   4.,   4.,  nan,  nan,  nan]])\n  ' #NEWLINE# T = np . atleast_3d ( T ) #NEWLINE# ( n , ch , cw ) = T . shape #NEWLINE# w = ( width if width else np . ceil ( np . sqrt ( n ) ) ) #NEWLINE# h = np . ceil ( ( n / float ( w ) ) ) #NEWLINE# R = np . vstack ( [ T , ( np . nan * np . zeros ( ( ( ( w * h ) - n ) , ch , cw ) ) ) ] ) #NEWLINE# R = R . reshape ( h , w , ch , cw ) #NEWLINE# R = np . concatenate ( ch , axis = 1 ) #NEWLINE# R = np . concatenate ( R , axis = 1 ) #NEWLINE# return R