Collecting info

Report a typo

Your task is to complete the collect_info() function that takes a NumPy array as input and returns a string containing information about the array's shape, number of dimensions, and total size.

The string should be formatted as follows:

"Shape: (dimension1,..., dimensionN); dimensions: N; size: total_size"

For example, you have a 3-dimensional NumPy array named threeD defined as:

threeD = np.array([[[1, 1, 1], [2, 2, 2]],
                   [[3, 3, 3], [4, 4, 4]]])

When you pass this threeD array to the collect_info function, it should return the string:

Shape: (2, 2, 3); dimensions: 3; size: 12"
Hint

Carefully review the methods from the Learning sizes theory section.

Write a program in Python 3
import numpy as np

def collect_info(array):
shape = ...
dimensions = ...
size = ...
return f'Shape: {shape}; dimensions: {dimensions}; size: {size}'
___

Create a free account to access the full topic