Skip to content

Instantly share code, notes, and snippets.

@jss367
Created July 22, 2018 04:42
Show Gist options
  • Save jss367/caf9d722938effe8dc253f3956f038c0 to your computer and use it in GitHub Desktop.
Save jss367/caf9d722938effe8dc253f3956f038c0 to your computer and use it in GitHub Desktop.
# Find the internal structure of a list or numpy array
def shape(lst):
ob_type = type(lst)
if ob_type == np.ndarray:
print("The size is " + str(lst.shape))
length = len(lst)
shp = tuple(shape(sub) if isinstance(sub, list) else 0 for sub in lst)
if any(x != 0 for x in shp):
return length, shp
else:
return length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment