【发布时间】:2020-06-07 05:08:22
【问题描述】:
请不要告诉我将其重塑为 2*1,因为这会将第二个 [0.] 发送到下一行。我想要与预期输出相同的输出。 我想要完全相同的答案,并且使用 reshape 不是强制性的。
def initialize_with_zeros(dim):
"""
This function creates a vector of zeros of shape (dim, 1) for w and initializes b to 0.
Argument:
dim -- size of the w vector we want (or number of parameters in this
case)
Returns:
w -- initialized vector of shape (dim, 1)
b -- initialized scalar (corresponds to the bias)
"""
### START CODE HERE ### (≈ 1 line of code)
w = np.zeros((dim,1))
b = 0
### END CODE HERE ###
assert(w.shape == ( dim,1))
assert(isinstance(b, float) or isinstance(b, int))
return w, b
dim = 2
w, b = initialize_with_zeros(dim)
print ("w " + str(w))
print ("b " + str(b))
我得到的输出是:
w [[ 0.]
[ 0.]]
b 0
预期输出:
w [[ 0.] [ 0.]]
b 0
【问题讨论】:
-
你能把它作为代码块中的文本而不是屏幕图片发布吗?
-
打印 w.tolist()