使用NumPy收集信息。

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

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

  1. import numpy as np
  2. def collect_info(array):
  3. shape = (2, 2, 3)
  4. dimensions = 3
  5. size = 12
  6. return f'Shape: {shape}; dimensions: {dimensions}; size: {size}'
  7. collect_info()

答案1

得分: 0

以下是您要翻译的代码部分:

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

请注意,我已将代码中的 HTML 编码字符 (') 替换为常规的单引号 (') 进行翻译。

英文:
  1. import numpy as np
  2. def collect_info(array):
  3. shape = array.shape
  4. dimensions = array.ndim
  5. size = array.size
  6. return f'Shape: {shape}; dimensions: {dimensions}; size: {size}'
  7. my_array = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
  8. result = collect_info(my_array)
  9. 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:

确定