def pretty_print_3d_array(array3D): # Determine the maximum number width for formatting maxNumWidth = max(len(str(abs(x))) for x in array3D.flatten() if x != 0) # Iterate through each layer for layerIndex in range(array3D.shape[0]): for rowIndex in range(array3D.shape[1]): for colIndex in range(array3D.shape[2]): element = array3D[layerIndex, rowIndex, colIndex] # Using format specifiers to align the output print(f"{element:{maxNumWidth}f}" if element != 0 else " " * maxNumWidth, end=" ") # Move to the next row print() # Add an empty line between layers for better readability print()