我仍然在Linspace上执行此操作,因为我更喜欢遵循此命令。
您可以按照以下格式创建:np.linspace(np.zeros(width)[0],np.full((1,width),-1)[0],height)
np.linspace(np.zeros(5)[0],np.full((1,5),-1)[0],5)
输出以下内容:
array([[ 0. , 0. , 0. , 0. , 0. ],
[-0.25, -0.25, -0.25, -0.25, -0.25],
[-0.5 , -0.5 , -0.5 , -0.5 , -0.5 ],
[-0.75, -0.75, -0.75, -0.75, -0.75],
[-1. , -1. , -1. , -1. , -1. ]])
添加.tranpose(),您将得到:
array([[ 0. , -0.25, -0.5 , -0.75, -1. ],
[ 0. , -0.25, -0.5 , -0.75, -1. ],
[ 0. , -0.25, -0.5 , -0.75, -1. ],
[ 0. , -0.25, -0.5 , -0.75, -1. ],
[ 0. , -0.25, -0.5 , -0.75, -1. ]])
xy = np.matrix([x, y])