如何将数组从 (280, 280, 3) 重塑为 (28, 28, 3) [英] How can i reshape an array from (280, 280, 3) to (28, 28, 3)

查看:16
本文介绍了如何将数组从 (280, 280, 3) 重塑为 (28, 28, 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写一个代码,我用 pygame 在屏幕上写一个数字,然后神经网络预测我写的数字.我的问题是我用 (28, 28, 3) 中的图像数组训练了我的神经网络.所以我试图重塑我的 (280, 280, 3) 数组.但是当我这样做时,我的数组是无.我使用 Python 3.7

Hi i tried to write a code, where i write a number on the screen with pygame and then a neural Network predicts the number i wrote. My problem is that i trained my neural network with image arrays in a (28, 28, 3). So i tried to reshape my (280, 280, 3) array. but when i do so my array is None. I use Python 3.7

string_image = pygame.image.tostring(screen, 'RGB')
temp_surf = pygame.image.fromstring(string_image, (280, 280), 'RGB')
array = pygame.surfarray.array3d(temp_surf)
array = array.resize((28, 28, 3))

有人可以帮忙吗?

推荐答案

如果您只想缩放 pygame.Surface,那么我推荐使用 pygame.transform.scale()pygame.transform.smoothscale().

If you just want to scale a pygame.Surface, then I recommend to use pygame.transform.scale() or pygame.transform.smoothscale().

例如:

temp_surf = pygame.image.fromstring(string_image, (280, 280), 'RGB')
scaled_surf = pygame.transform.smoothscale(temp_surf, (28, 28))
array = pygame.surfarray.array3d(scaled_surf)

这篇关于如何将数组从 (280, 280, 3) 重塑为 (28, 28, 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆