【发布时间】:2018-04-03 05:07:08
【问题描述】:
我有一个函数可以根据给定的 x 构建多项式:[1, x^2,x^3,x^4,...,x^degree]
def build_poly(x, degree):
"""polynomial basis functions for input data x, for j=0 up to j=degree."""
D = len(x)
polyome = np.ones((D, 1))
for i in range(1, degree+1):
polyome = np.c_[polyome, x**i]
return polyome
现在,我想计算给定 x 的多项式,但忽略 sume 值。
因此,这就是我所做的:
创建 X:
x=np.array([[1,2,3],[4,5,6]])])
我用我想省略的方式掩盖了这个值:
masked_x= np.ma.masked_equal(x, 5)
print(masked_x)
但是当我进行计算时:
print(build_poly(masked_x,2))
遮罩消失了。 为什么? 我想让程序省略被屏蔽的元素
【问题讨论】:
-
在
for语句之后立即添加print(i,x**i)。
标签: python numpy computation