使用NumPy收集信息。

huangapple go评论70阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年5月11日 03:19:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定