Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

collecting information with NumPy

Unable to solve the problem. My answer is not correct. Help me to understand
Task:wWrite a function that takes a NumPy array and returns its shape, dimensions, and size, collected in a string

import numpy as np


def collect_info(array):
    shape = (2, 2, 3)
    dimensions = 3
    size = 12
    return f'Shape: {shape}; dimensions: {dimensions}; size: {size}'

collect_info()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import numpy as np

def collect_info(array):
    shape = array.shape
    dimensions = array.ndim
    size = array.size
    return f'Shape: {shape}; dimensions: {dimensions}; size: {size}'
my_array = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
result = collect_info(my_array)
print(result)

I hope this helps!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading