Created
July 22, 2018 04:42
-
-
Save jss367/caf9d722938effe8dc253f3956f038c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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