Vijayanjali
Vijayanjali

Reputation: 31

Python list function ndim and size

I am following Tensorflow tutorial on datacamp.com. https://www.datacamp.com/community/tutorials/tensorflow-tutorial#gs.ljKz3uI

I am stuck at this point of code where the code refers to print size and dimension of the list using ndim and size. I get an error "list object has no attribute ndim."

` import os

 import skimage

 import pdb

 from skimage import data
ROOT_PATH = "/tmp/"
train_data_directory =os.path.join(ROOT_PATH,
\mozilla_vijaya0/Training")
test_data_directory = os.path.join(ROOT_PATH, 
"mozilla_vijaya0/Testing")
def load_data(data_directory):
directories = [d for d in os.listdir(data_directory) 
               if os.path.isdir(os.path.join(data_directory, d))]
 labels = []
images = []
for d in directories:
    label_directory = os.path.join(data_directory, d)
    file_names = [os.path.join(label_directory, f) 
                  for f in os.listdir(label_directory) 
                  if f.endswith(".ppm")]
    for f in file_names:
        images.append(skimage.data.imread(f))
        labels.append(int(d))
return images, labels

images, labels = load_data(train_data_directory)
print(images.ndim)
print(images.size)
images[0]`

what is the right way to display the dimensions and size of the list.

Upvotes: 1

Views: 3065

Answers (1)

prudhvi Indana
prudhvi Indana

Reputation: 829

convert images to numpy array using below command

images = np.array(images)

now you will be able to run

print(images.ndim)
print(images.size)

Upvotes: 3

Related Questions