【问题标题】:Create a vector length n with n entries 'x'创建一个长度为 n 的向量,其中包含 n 个条目 \'x\'
【发布时间】:2022-12-04 11:31:29
【问题描述】:

Example:

n = 5
x = 3.5
Output:
array([3.5, 3.5, 3.5, 3.5, 3.5])

My code:

import numpy as np
def init_all_x(n, x):
    np.all = [x]*n
    return np.all
init_all_x(5, 3.5)

My question:

Why init_all_x(5, 3.5).shape cannot run?

If my code is wrong, what is the correct code? Thank you!

    标签: python numpy vector linear-algebra shapes


    【解决方案1】:
    猜你喜欢
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2019-06-16
    • 2021-08-03
    • 2021-01-22
    • 2011-02-17
    相关资源
    最近更新 更多