英文:
collecting information with NumPy
问题
"无法解决问题。我的答案不正确。帮助我理解\n任务:编写一个接受NumPy数组并返回其形状、维度和大小的函数,将它们汇总在一个字符串中\n\n\nimport numpy as np\n\ndef collect_info(array):\n shape = (2, 2, 3)\n dimensions = 3\n size = 12\n return f'形状:{shape}; 维度:{dimensions}; 大小:{size}'\n\ncollect_info()"
英文:
Unable to solve the problem. My answer is not correct. Help me to understand
Task: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()
答案1
得分: 0
以下是您要翻译的代码部分:
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)
请注意,我已将代码中的 HTML 编码字符 (') 替换为常规的单引号 (') 进行翻译。
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论