gpt4 book ai didi

python - 将齐次坐标 (x0=1) 添加到 numpy 中的图像

转载 作者:行者123 更新时间:2023-11-30 09:40:28 25 4
gpt4 key购买 nike

我有7张尺寸为29*29的图像,我想添加一个同质坐标(增强它们with feature, x0=1) to all 7 images,但我不知道该怎么做。

我的原始图像尺寸是

images.shape 
#(7, 29, 29)

我尝试过是压缩 np.ones() 但它最终为第一个特征创建单独的数组,导致尺寸为 7*2

np.array([list(a) for a in zip(np.ones([7,1]),images_all[:,:])]).shape
#(7,2)
#
#[[array([1.]),
# array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
....

如您所见,它添加 1 作为单独的数组,并作为第一个元素追加。

此外,我尝试循环遍历图像并在第一个元素处插入 1,但它使尺寸为 30 并给出错误

for i in range(len(images)):
images[i][0] = np.insert(images[i][0], 0, 1., axis=0)

ValueError: could not broadcast input array from shape (30) into shape (29)

最佳答案

首先创建一个更大的数组, reshape 原始数组并更新更大的数组。

padded_images = np.ones((7,29*29+1))
padded_images[:,1:] = images.reshape(7,29*29)

关于python - 将齐次坐标 (x0=1) 添加到 numpy 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59017191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com