我如何将数组从(280,280,3)整形为(28,28,3) [英] How can i reshape an array from (280, 280, 3) to (28, 28, 3)
本文介绍了我如何将数组从(280,280,3)整形为(28,28,3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试编写代码,我用pygame在屏幕上写了一个数字,然后神经网络预测了我写的数字.我的问题是我用(28,28,3)中的图像阵列训练了我的神经网络.所以我试图重塑我的(280,280,3)数组.但是当我这样做时,我的数组是None.我使用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.transform.scale()
或
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屋!
查看全文