我需要加速我的代码,我还需要使用 += i ,因为 sure:for i in nums: sumof += i,它的 peivets 内存块
I need to speed up my code, Also I need to use += i , for sure:for i in nums: sumof += i, its peivets memory block
我尝试将我的 argmax 转换为 array.index(max(array))
我将不胜感激任何帮助。
我需要加快我的代码。
此代码仅适用于一张图片,我将在一分钟内处理大约 20 张图片。所以这就是为什么我尝试让它尽可能快。
import time
import numpy as np
#tab = [0.061,0.001,0.022,0.002,0.015,0.021,0.066,0.005,0.053,0.018,0.011,0.024,0.052,0.021,0.077,0.010,0.045,0.017,0.016,0.007,0.071,0.167,0.052,0.016,0.017,0.004,0.009,0.014,0.001,0.059,0.018,0.008,0.004,0.009,0.009]#tabK = [0.009,0.003,0.002,0.001,0.157,0.003,0.067,0.005,0.006,0.002,0.012,0.005,0.033,0.002,0.007,0.010,0.001,0.008,0.037,0.008,0.377,0.011,0.043,0.009,0.004,0.002,0.013,0.016,0.004,0.005,0.057,0.013,0.023,0.026,0.018]CATEGORIES = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z"]
#KOLEJNOSC ZNAKOW W TABLICY JEST ODWROCONA
CATEGORIES = ["0","1","2","3","4","5","6","7","8","9",
"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","R","S","T","U",
"V","W","X","Y","Z"]
KR887JJ = [[0.002,0.006,0.004,0.045,0.002,0.017,0.006,0.077,0.001,0.035,0.042,0.005,0.004,0.039,0.001,0.002,0.001,0.008,0.058,0.352,0.002,0.007,0.017,0.004,0.007,0.007,0.007,0.004,0.005,0.009,0.089,0.036,0.053,0.041,0.004],[0.003,0.007,0.005,0.075,0.001,0.020,0.006,0.044,0.002,0.035,0.026,0.004,0.004,0.033,0.001,0.001,0.003,0.008,0.049,0.360,0.002,0.007,0.021,0.005,0.009,0.003,0.008,0.007,0.003,0.014,0.092,0.048,0.058,0.031,0.004],[0.002,0.000,0.025,0.012,0.006,0.002,0.001,0.627,0.006,0.021,0.022,0.008,0.004,0.006,0.004,0.033,0.000,0.006,0.011,0.009,0.002,0.002,0.009,0.000,0.002,0.040,0.007,0.005,0.015,0.000,0.035,0.001,0.008,0.015,0.053],[0.056,0.008,0.023,0.038,0.015,0.007,0.050,0.006,0.412,0.004,0.005,0.027,0.011,0.005,0.021,0.007,0.073,0.024,0.012,0.005,0.013,0.005,0.027,0.003,0.015,0.001,0.005,0.074,0.002,0.022,0.005,0.011,0.002,0.001,0.006],[0.025,0.011,0.025,0.034,0.018,0.027,0.090,0.008,0.258,0.006,0.007,0.026,0.016,0.008,0.026,0.011,0.079,0.030,0.026,0.008,0.018,0.011,0.033,0.003,0.016,0.001,0.003,0.106,0.004,0.021,0.012,0.013,0.003,0.005,0.014],[0.048,0.027,0.019,0.002,0.028,0.002,0.008,0.017,0.041,0.014,0.012,0.022,0.031,0.005,0.045,0.100,0.004,0.031,0.033,0.002,0.029,0.006,0.021,0.032,0.008,0.038,0.317,0.007,0.017,0.004,0.018,0.005,0.003,0.004,0.002],[0.013,0.002,0.002,0.000,0.164,0.001,0.060,0.004,0.006,0.002,0.018,0.003,0.035,0.002,0.008,0.008,0.001,0.008,0.028,0.005,0.383,0.013,0.063,0.010,0.004,0.002,0.014,0.016,0.002,0.005,0.048,0.011,0.028,0.017,0.012]]
[[0.004,0.007,0.005,0.042,0.002,0.014,0.011,0.054,0.002,0.032,0.051,0.005,0.005,0.044,0.001,0.002,0.002,0.008,0.056,0.389,0.003,0.008,0.023,0.005,0.009,0.005,0.009,0.006,0.004,0.010,0.070,0.029,0.049,0.031,0.005],[0.005,0.005,0.005,0.034,0.002,0.006,0.005,0.083,0.002,0.062,0.053,0.004,0.006,0.039,0.001,0.002,0.001,0.008,0.055,0.348,0.002,0.005,0.020,0.005,0.011,0.011,0.018,0.004,0.005,0.008,0.086,0.018,0.055,0.020,0.004],[0.001,0.001,0.024,0.009,0.013,0.003,0.002,0.499,0.006,0.011,0.022,0.011,0.007,0.006,0.006,0.048,0.000,0.008,0.013,0.009,0.004,0.002,0.007,0.000,0.002,0.053,0.009,0.007,0.030,0.000,0.030,0.001,0.009,0.021,0.123],[0.039,0.008,0.029,0.041,0.013,0.008,0.054,0.005,0.369,0.004,0.005,0.023,0.011,0.005,0.020,0.005,0.100,0.022,0.012,0.005,0.012,0.007,0.028,0.002,0.015,0.000,0.003,0.102,0.001,0.021,0.006,0.012,0.002,0.002,0.007],[0.031,0.007,0.018,0.032,0.015,0.017,0.075,0.008,0.365,0.005,0.005,0.028,0.015,0.005,0.022,0.011,0.075,0.027,0.014,0.005,0.020,0.006,0.025,0.002,0.014,0.001,0.004,0.099,0.003,0.016,0.008,0.009,0.002,0.002,0.010],[0.046,0.022,0.022,0.002,0.031,0.003,0.008,0.022,0.047,0.011,0.010,0.039,0.035,0.005,0.048,0.110,0.002,0.028,0.031,0.003,0.029,0.006,0.016,0.022,0.007,0.059,0.289,0.005,0.016,0.003,0.013,0.004,0.002,0.004,0.003],[0.019,0.004,0.002,0.000,0.134,0.004,0.088,0.006,0.004,0.003,0.016,0.007,0.037,0.004,0.016,0.014,0.002,0.014,0.026,0.005,0.342,0.019,0.049,0.024,0.004,0.003,0.021,0.009,0.005,0.009,0.049,0.012,0.017,0.026,0.006]]
[[0.002,0.005,0.005,0.046,0.002,0.014,0.008,0.073,0.002,0.023,0.042,0.004,0.007,0.027,0.001,0.003,0.001,0.006,0.047,0.384,0.005,0.006,0.015,0.003,0.006,0.004,0.011,0.006,0.006,0.005,0.088,0.027,0.066,0.040,0.010],[0.002,0.005,0.005,0.039,0.002,0.009,0.005,0.089,0.001,0.036,0.043,0.004,0.006,0.026,0.001,0.002,0.001,0.006,0.051,0.387,0.003,0.005,0.014,0.003,0.007,0.007,0.014,0.004,0.007,0.005,0.090,0.022,0.064,0.030,0.006],[0.002,0.001,0.014,0.011,0.020,0.005,0.004,0.282,0.005,0.012,0.022,0.011,0.009,0.010,0.008,0.041,0.000,0.017,0.030,0.019,0.009,0.003,0.009,0.000,0.004,0.053,0.010,0.016,0.049,0.000,0.043,0.002,0.017,0.037,0.224],[0.028,0.015,0.029,0.039,0.023,0.020,0.097,0.008,0.239,0.004,0.009,0.021,0.019,0.008,0.017,0.008,0.082,0.023,0.025,0.012,0.020,0.010,0.037,0.003,0.016,0.001,0.003,0.110,0.003,0.019,0.012,0.014,0.004,0.005,0.015],[0.037,0.013,0.035,0.053,0.025,0.022,0.057,0.017,0.250,0.005,0.009,0.037,0.025,0.008,0.029,0.013,0.057,0.029,0.029,0.009,0.015,0.009,0.027,0.002,0.020,0.002,0.006,0.092,0.006,0.012,0.011,0.011,0.003,0.004,0.021],[0.036,0.022,0.024,0.003,0.022,0.004,0.011,0.019,0.069,0.014,0.011,0.035,0.045,0.006,0.057,0.096,0.004,0.037,0.030,0.004,0.039,0.007,0.021,0.018,0.010,0.031,0.256,0.013,0.018,0.003,0.018,0.005,0.004,0.006,0.004],[0.015,0.003,0.002,0.000,0.174,0.004,0.085,0.008,0.005,0.002,0.015,0.008,0.028,0.003,0.013,0.016,0.001,0.015,0.029,0.004,0.357,0.013,0.043,0.017,0.003,0.003,0.017,0.010,0.004,0.007,0.037,0.013,0.015,0.020,0.010]]
[[0.005,0.006,0.006,0.055,0.002,0.017,0.009,0.076,0.003,0.035,0.032,0.007,0.005,0.050,0.001,0.002,0.002,0.011,0.050,0.391,0.002,0.005,0.018,0.003,0.012,0.009,0.009,0.005,0.005,0.012,0.068,0.032,0.032,0.017,0.006],[0.009,0.005,0.007,0.064,0.002,0.022,0.009,0.040,0.003,0.030,0.026,0.010,0.006,0.069,0.001,0.001,0.004,0.011,0.040,0.379,0.002,0.009,0.021,0.005,0.017,0.007,0.009,0.005,0.003,0.034,0.063,0.035,0.029,0.017,0.006],[0.001,0.001,0.014,0.011,0.011,0.004,0.003,0.458,0.004,0.012,0.023,0.010,0.007,0.009,0.006,0.039,0.000,0.012,0.016,0.014,0.005,0.003,0.007,0.000,0.002,0.052,0.008,0.009,0.039,0.000,0.036,0.001,0.013,0.032,0.139],[0.042,0.012,0.023,0.029,0.043,0.015,0.111,0.010,0.235,0.004,0.009,0.036,0.023,0.010,0.018,0.010,0.039,0.029,0.024,0.012,0.025,0.009,0.041,0.003,0.019,0.002,0.005,0.084,0.004,0.018,0.013,0.012,0.004,0.005,0.023],[0.030,0.008,0.017,0.033,0.011,0.020,0.103,0.009,0.289,0.004,0.006,0.030,0.022,0.007,0.021,0.011,0.108,0.031,0.013,0.008,0.020,0.006,0.023,0.002,0.018,0.001,0.004,0.102,0.005,0.012,0.007,0.007,0.002,0.003,0.009],[0.034,0.024,0.018,0.003,0.025,0.005,0.008,0.025,0.053,0.010,0.008,0.045,0.036,0.006,0.050,0.119,0.002,0.035,0.028,0.003,0.029,0.005,0.014,0.017,0.007,0.060,0.275,0.006,0.019,0.002,0.013,0.004,0.003,0.006,0.005],[0.016,0.004,0.002,0.000,0.130,0.003,0.080,0.005,0.004,0.003,0.017,0.005,0.038,0.002,0.015,0.014,0.002,0.011,0.027,0.004,0.378,0.016,0.051,0.019,0.004,0.002,0.020,0.012,0.004,0.006,0.040,0.013,0.023,0.020,0.008]]
[[0.006,0.004,0.007,0.052,0.002,0.012,0.005,0.066,0.002,0.043,0.036,0.007,0.007,0.051,0.001,0.001,0.002,0.008,0.037,0.401,0.002,0.008,0.017,0.004,0.013,0.010,0.014,0.004,0.004,0.016,0.077,0.021,0.038,0.018,0.006],[0.001,0.001,0.012,0.008,0.013,0.004,0.002,0.462,0.004,0.011,0.022,0.008,0.006,0.006,0.006,0.052,0.000,0.012,0.018,0.012,0.005,0.002,0.007,0.000,0.002,0.046,0.009,0.009,0.040,0.000,0.039,0.002,0.012,0.031,0.136],[0.004,0.003,0.007,0.042,0.001,0.008,0.005,0.060,0.002,0.062,0.050,0.005,0.004,0.053,0.000,0.001,0.002,0.006,0.033,0.422,0.001,0.008,0.017,0.004,0.011,0.007,0.010,0.003,0.002,0.013,0.065,0.024,0.045,0.017,0.003],[0.029,0.015,0.032,0.058,0.018,0.013,0.067,0.012,0.287,0.006,0.010,0.025,0.016,0.007,0.017,0.009,0.059,0.023,0.026,0.011,0.016,0.006,0.033,0.003,0.017,0.001,0.006,0.118,0.004,0.014,0.009,0.012,0.004,0.003,0.012],[0.056,0.011,0.024,0.034,0.027,0.015,0.065,0.013,0.271,0.006,0.007,0.062,0.028,0.013,0.026,0.014,0.030,0.039,0.027,0.011,0.019,0.006,0.031,0.003,0.027,0.005,0.009,0.061,0.006,0.014,0.011,0.006,0.002,0.004,0.016],[0.041,0.020,0.022,0.002,0.019,0.004,0.007,0.024,0.046,0.016,0.008,0.051,0.036,0.006,0.051,0.109,0.002,0.030,0.027,0.003,0.024,0.005,0.015,0.017,0.008,0.067,0.286,0.005,0.015,0.003,0.014,0.003,0.002,0.005,0.003],[0.014,0.003,0.002,0.000,0.106,0.007,0.079,0.007,0.004,0.003,0.014,0.010,0.041,0.004,0.013,0.011,0.001,0.014,0.031,0.007,0.377,0.022,0.049,0.017,0.004,0.003,0.014,0.009,0.004,0.009,0.050,0.013,0.016,0.034,0.008]]
[[0.008,0.004,0.008,0.064,0.001,0.018,0.009,0.041,0.003,0.043,0.035,0.008,0.005,0.076,0.001,0.001,0.004,0.009,0.037,0.382,0.001,0.011,0.024,0.005,0.015,0.006,0.007,0.005,0.002,0.030,0.057,0.031,0.029,0.017,0.004],[0.002,0.004,0.004,0.044,0.001,0.012,0.005,0.068,0.001,0.043,0.052,0.003,0.005,0.030,0.001,0.002,0.001,0.007,0.041,0.350,0.003,0.007,0.019,0.005,0.007,0.004,0.011,0.005,0.003,0.007,0.099,0.035,0.076,0.038,0.004],[0.001,0.001,0.015,0.011,0.009,0.004,0.002,0.517,0.004,0.012,0.028,0.007,0.005,0.007,0.005,0.035,0.000,0.011,0.014,0.012,0.005,0.003,0.010,0.000,0.002,0.030,0.006,0.009,0.029,0.000,0.039,0.002,0.016,0.034,0.114],[0.026,0.010,0.036,0.064,0.011,0.009,0.052,0.010,0.360,0.004,0.007,0.022,0.015,0.005,0.017,0.006,0.067,0.019,0.017,0.008,0.013,0.006,0.026,0.002,0.015,0.001,0.004,0.121,0.003,0.011,0.006,0.010,0.003,0.002,0.011],[0.044,0.017,0.027,0.037,0.024,0.016,0.079,0.010,0.259,0.006,0.009,0.032,0.023,0.009,0.022,0.012,0.064,0.031,0.026,0.010,0.019,0.007,0.034,0.004,0.021,0.002,0.007,0.086,0.005,0.018,0.011,0.011,0.003,0.003,0.011],[0.033,0.013,0.021,0.002,0.014,0.003,0.006,0.023,0.033,0.015,0.009,0.048,0.040,0.007,0.056,0.098,0.002,0.032,0.023,0.003,0.023,0.006,0.013,0.015,0.009,0.069,0.331,0.005,0.018,0.002,0.012,0.003,0.002,0.005,0.003],[0.017,0.004,0.002,0.000,0.096,0.008,0.095,0.007,0.004,0.003,0.013,0.012,0.045,0.006,0.017,0.013,0.002,0.016,0.029,0.007,0.360,0.023,0.045,0.023,0.005,0.004,0.018,0.008,0.005,0.010,0.042,0.011,0.013,0.032,0.007]]
[[0.007,0.004,0.007,0.082,0.002,0.023,0.009,0.029,0.003,0.024,0.024,0.008,0.006,0.062,0.001,0.001,0.005,0.009,0.032,0.391,0.002,0.012,0.020,0.005,0.016,0.004,0.006,0.006,0.002,0.037,0.061,0.041,0.033,0.019,0.006],[0.004,0.004,0.008,0.078,0.001,0.013,0.005,0.059,0.002,0.044,0.041,0.006,0.005,0.052,0.001,0.001,0.002,0.008,0.036,0.366,0.001,0.010,0.015,0.003,0.011,0.008,0.008,0.005,0.004,0.015,0.074,0.035,0.045,0.023,0.007],[0.001,0.001,0.013,0.010,0.015,0.006,0.004,0.299,0.004,0.011,0.021,0.011,0.009,0.010,0.009,0.044,0.000,0.021,0.023,0.017,0.008,0.004,0.007,0.000,0.003,0.056,0.008,0.014,0.056,0.000,0.040,0.002,0.016,0.039,0.217],[0.021,0.011,0.022,0.060,0.018,0.026,0.090,0.014,0.234,0.005,0.011,0.025,0.016,0.009,0.015,0.011,0.052,0.030,0.029,0.015,0.019,0.007,0.030,0.003,0.016,0.001,0.003,0.134,0.006,0.013,0.011,0.014,0.004,0.005,0.020],[0.031,0.012,0.027,0.036,0.023,0.020,0.053,0.018,0.269,0.006,0.008,0.029,0.036,0.007,0.029,0.021,0.046,0.030,0.028,0.009,0.023,0.007,0.027,0.003,0.020,0.002,0.010,0.098,0.010,0.009,0.016,0.009,0.004,0.005,0.018],[0.036,0.019,0.017,0.002,0.027,0.004,0.009,0.027,0.063,0.012,0.008,0.045,0.035,0.006,0.050,0.140,0.002,0.036,0.030,0.003,0.031,0.004,0.017,0.016,0.007,0.055,0.239,0.007,0.018,0.002,0.014,0.004,0.003,0.006,0.004],[0.018,0.004,0.002,0.000,0.186,0.004,0.107,0.005,0.005,0.003,0.010,0.008,0.041,0.004,0.017,0.018,0.001,0.012,0.034,0.004,0.300,0.014,0.036,0.018,0.004,0.004,0.020,0.010,0.005,0.008,0.049,0.009,0.011,0.020,0.008]]
start = time.time()
for sing in KR887JJ:
print(CATEGORIES[np.argmax(sing)])
#print(CATEGORIES[sing.index(max(sing))])
def list_mean(nums):
sumof = 0
num_of = len(nums)
mean = 0
for i in nums:
sumof += i
mean = sumof / num_of
return float(mean)
end = time.time()
print(f"Runtime of the program is {end - start}")
而且我 100% 需要这部分,因为我在 nums:
求和+=我。像这样的迭代不会占用大量内存,因为它一直在计数,而不是大块内存和平。
提前致谢!
np.argmax 并不比 array.index(np.max(array)) 慢,但是 list_mean 可以更有效率:如果你想要一个完整的 python实现,可以使用
sum(nums)/len(nums)
或者更高效:
np.mean(nums)
(您已经使用过数组)
或多或少:
导入时间
将 numpy 导入为 np
#数组中字符的顺序颠倒了
类别 = ["0","1","2","3","4","5","6","7","8","9","A","B" "C","D","E","F","G","H","I","J","K","L","M","N"," O","P","R","S","T","U","V","W","X","Y","Z"]
KR887JJ = [[0.002,0.006,0.004,0.045,0.002,0.017,0.006,0.077,0.001,0.035,0.042,0.005,0.004,0.039,0.001,0.002,0.052,0.001,0.0.0 0.052,0.001,0.0 ,0.017,0.004,0.007,0.007,0.007,0.004,0.005,0.009,0.089,0.036,0.053,0.041,0.004],[0.003,0.007,0.005,0.075,0.0.03,0.001,0.046,0.046,0.046,0.004] ,0.004 , 0.026.0.00,0.00,0.00,0,033.0.001.0.001.0.003.0.00,0,0,049.0.360.0.002.0.00,0.00,0,0,021.0.005.0.00,0.00,0.003.0.0.0,0,0,0 .0.00,0.00,0.003.0.014.0.092.092.0,092.0,048,0,058.0,031,0.004 ],[0.002,0.000,0.025,0.012,0.006,0.002,0.001,0.627,0.006.0.00421,0.0021,0.006.0.00221 ,0.006,0.004,0.033,0.000,0.006,0.0,0.020,0.009,0.020,0.009,0.020 ,0.002,0.040,0.007,0.005,0.015,0.000,0.035,0.001,0.008,0.056[0.056],0.008,0.056[] ,0.023,0.038,0.015,0.007,0.050.050.10.107,0.0.0.0206,0.412,0.412,006 0.005,021,021,007,007,073,073,024.024.024.012,012,0.0.0.13.0.bes0.0.0.bs-0.0.0.100,0.0.0.100,000.0.100,00s.0.bes。 0.022,0.005,0.011,0.002,0.061,0.025,0.034,0.018,018,0.027,027,0.090.090,0.008,008,0.258,0.6,006,006,007,007,026,026,016,0.0.88.8.8.8.8m.08.8.8m.08.8m,0.08.8.8m,0.0.8,008,000.08.cn, 00s.008,000.008,000.008,000.08.8.crel 0。 033,0.003,0.016,0.001,0.003,0.106,0.004,0.021,0.012,0.013,0.003,0.005,0.014],[0.048,0.027,0.019,0.002,0.028,0.002,0108,0.0035,0.0025,0.0025,0.0217 ,0.100,0.004,0.031,0.033,0.002,0.029,029,006,0.06,021,021,0.032,032,0.008,008,038,038,0.317,0.007,007,007,017,017,004,004,0055550.0.0.0.0.0.0.c.0050.0.c. 00. 00. 00. 00. 00. 00. 00. 00p0. 00p0.0.bay0.0C.0.0.it.0.0.its.0.0.0.it.0.0.0.it.0.0.0.bhis。 0.00,0,0.006.0.002.0.018.0.003.0,0,035.0,0,002.0.008.0.00,0.00,0.001,0,0.00,0.008.0,028.0.005.0 0.002,0.014,0.016,0.002,0.018185,0.002,0.01815 ,0.017,0.012]]
[[0.004,0.007,0.005,0.042,0.002,0.014,0.011,0.054,0.002,0.032,0.051,0.005,0.005,0.044,0.001,0.002,0.002,0.008,0.03,0.056,0.389,0.003 0.009,0.005,0.009 ,0.006,0.004,0.010,0.070,0.029,0.049,0.031,0.005],[0.005,0.005,0.005,0.034,0.002,0.006,0.005,0.0.0.083,0.002,0.06 0.039,0.00101,0.002,0.002,0.06 0.055,0.348,0.002,0.005,020,020,005,005,011,011,011,018,018,0.018,0.004,0.005,005,008,008,0.086,086,018,018,0555,055,04.040.040 0.040 0.0.0.0.00,000.000.00,000.000.00,000. 000.000.bas 0.001,0.009,0.021,0.123],[0.039,0.008,0.0.029,029,041,041,0.013,013,0.008,008,0.054,0.005,005,005,0.369,0.36,0.0.4,05,05,005,0.0.0.13,0.0.13,0.0.b,0.13,0.0.13,0.0.13,0.0.13,00.0.bhist ,0.002,0.015,0.000,0.003,0.102,0.001,0.021,0.006,0.012,0.002,0.002,0.007,0.0.017,0.075,0.008,0.365,0.005,0.005,0.028,0.01.015,0.028,0.01.015,0.028,0.01.015,0 ,0.027,0.014,0.005,0.020,0.006,0.025,0.002,0.014, 0.001,0.004,0.099,0.003,016,016,0.008,009,009,009,002,002,002,0.010] ,0.028,0.031,0.003,0.029,0.006,0.016,0.022,0.007,0.059,0.289,0.005,0.016,0.003,0.013,0.004,0.002,0.004,0.003] 0.000.0.134.0.00,0,088,0.006.0.00,0.003 .0.016.0,016.0,037.0.00,0,016.0,014.0.002.0.014.0.026.026.026,0.005.0.342.0.019.0.049.0,0,024.0.00,0.003.0.021,0,021,0.0109,0.0109,0.0109,0.0109,0.0109 ,0.017,0.026,0.006]]
[[0.002,0.005,0.005,0.046,0.002,0.014,0.008,0.073,0.002,0.023,0.042,0.004,0.007,0.027,0.001,0.003,0.001,0.006,0.03,0.047,0.384,0.005 0.006,0.004,0.011 ,0.006,0.006,0.005,0.088,0.027,0.066,0.040,0.010]. 0.026,0.001,0.002,0.001,0.006,0.051,0.387,0.003,0.005,0.014,0.003,0.07,0.007,0.014,0.014,0.014,0.014 0.005,0.090,0.022,0.064,0.030 0.014.0.011.0,020,0.00,0.00,0.00,0.282.0.005.0.012.022,0.011,0.00.0.010.010.010,0.00,0,040.0.037.010 ,0.00,0.003.0.00,0.0,000.0 0.016,0.049,0.000,0.043,0.002,0.017,0.037,0.224]. 0.082,0.023,0.025,0.012,0.020,0.010,0.037,01.0.0103,0.00163,0.037,01.001063,0.0163,0 ,0.003,0.019,0.012,0.014,0.004,0.005,0.037,0.5,0.0.022,0.057,0.017,0.250,0.005,0.009,0.037,0.025,0.008,0.029,0.013,0.019,0.059,0.027,0.027,0.029 ,0.009,0.027,0.002,0.020, 0.002,0.006,0.092,0.006,0.012,012,011,011,011,011,0.003,004.004,0.021] ,0.003,0.018,0.005,0.035,0.006,0.004] 0.000.0.174.0.00,0,085.0.00,0.005.0.002.0,015.0.00,0,028.0.003.0.013.0,016.0,0,000.0,0,05.09.0,02.01 ,0.357.0.019.013.0.043.0,0,017,0.003.0.003.0.017.0.010, 0.004,0.007,0.037,0.013,0.015,0.020,0.010]]
[[0.005,0.006,0.006,0.055,0.002,0.017,0.009,0.076,0.003,0.035,0.032,0.007,0.005,0.050,0.001,0.002,0.002,0.011,0.0.050,0.0120,0.0120,0.0120,0.0121,0.011,0.0.050,0.0120,0.0120 ,0.005,0.005,0.012,0.068,0.032,0.032,0.017,0.006],[0.009,0.005,0.007,0.064,0.002,0.022,0.009,0.0,0,0.040,0.003,0.03 0.069,0.04,0.000 0.011,0.040,0.379,0.002,009,009,0.021,021,0.005,017,017,0.007,007,0.009,009,009,005,005,003,003,0.034.063,063,0.03,035,029.029.0.0.9.ctel .010.0.00,0.00,0,0,0,0,039.0.000.0.012.0.016.0,016.014,0.005.0.003.0.00,0.00,0.000.0.002.0.052.0008, 0.009,0.039,0.000.0.0136,0.036, ,0.032,0.139]. 0.039,0.029,0.024,0.012,0.025,0.009,0.041,0.003,0.019,0.002,0.005,0.084,0.004,0.018,0.013,0.012,0.004,0,01,0.012,0.012,0.012,0.012,0.004,0.01,0.012,0.012 018 0.020,0.103,0.009,0.289,0.004,0.006,0.030,0.022,0.007,0.021,0.011,0.108,0.031,0.013,0.008,0.020,0.006,0.023,0.002,0.018, 0.001,0.004,0.102,0.005,012,012,0.007,007,007,007,002,002,0.003,0.009] ,0.002,0.013,0.004,0.003,0.006,0.005] 0.000.0.130.0.003.0.080.0,0.00,0.00,0.003.0.017.0,0,038.0,0,002.0.015.0.014.0.002.0.0.02711 0.004,0.006,0.040,0.013,0.023,0.020,0.008]]
[[0.006,0.004,0.007,0.052,0.002,0.012,0.005,0.066,0.002,0.043,0.036,0.007,0.007,0.051,0.001,0.001,0.002,0.008,0.0.037,0.01301,0.01301,0.01301,0.008,0.0.037,0.01301,0.0102 ,0.004,0.004,0.016,0.077,0.021,0.038,0.018,0.006],[0.001,0.001,0.012,0.008,0.013,0.004,0.002,0.08,0.06,0.022,0.014,0.012,0.056,0.02,0.066 0.012,0.018,0.012,0.005,005,002,002,007,007,0.000.000.002,002,04.046,0.009,009,009,009,009,0.040.000.000.000.000.000.039,039,002,002,002,012,012,0.0.00.0.00.00.00.00.00.ly. 00. 00. 00. 00. 00. 00. 00. 00p0. 00p. 00,000.00p0.w.ars.0.去不从而.050,0.00,0,053.0.0.000,0.001.0.002.0.006.0.033,0,033,0 0.003,0.002,0.013,0.065,0.024,0.045,0.017,0.003],[0.029,0.015,0.0138,0.0580,0.0580,0.029 0.067,0.012,0.287,0.006,0.09,0.010,0.025,0.017,0.010,0.025,0.017 0.059,0.023,0.026,0.011,0.016,0.006,0.033,0.003,0.017,0.001,0.006,0.118,0.004,0.014,0.009 ,0.012,0.004,0.003,0.012],[0.056,0.024] 0.015,0.065,0.013,0.271,0.006,0.007,0.062,0.028,0.013,0.026,0.014,0.030,0.039,0.0160,0.0127,0.030,0.039,0.0160,0.0127 ,0.003,0.027, 0.005,0.009,0.061,0.006,0.014,0.011,0.006,0.002,0.004,0.016],[0.041,0.020,0.022,0.002,0.019,0.004,0.007,0.024,0.0.36,0.016,0.016,0.016,0.019,0.024,0.0.36,0.016,0.016,0.019 ,0.002,0.030,0.027,0.003,0.024,0.005,0.015,0.017,0.008,0.067,0.286,0.005,0.015,0.003,0.014,0.003,0.002,0.005,0.003 0.000.0.106.0.00,0,079.0.00,0.004. 0.003.0.014.0.010.041.0.00,0.013.010.011,0.001.0,014.0.031,0.007.0 0.004,0.009,0.050,0.013,0.016,0.034,0.008]]
[[0.008,0.004,0.008,0.064,0.001,0.018,0.009,0.041,0.003,0.043,0.035,0.008,0.005,0.076,0.001,0.001,0.004,0.009,0.0.037,0.0160,0.037,0.0182,0.0182,0.015 ,0.005,0.002,0.030,0.057,0.031,0.029,0.017,0.004],[0.002,0.004,0.004,0.044,0.001,0.012,0.005,0.32,0.068,0.001,0.04 0,030,0.07,0.012 0.041,0.350,0.003,007,007,019,0.005,005,007,007,0.004,004,0.011,011,0.005,005,003,003,007,007,099999,0.035,035,076,076,0.048 0.048 0.0.0.0.0.0.0.bes.0.0.bes.0.0.bes.0.0.bes.0.000.00.0.00 n.0.00,000.00.0.,00s.0,000.00.0.bes ,0.005.0.00,0.00,0.00,0.00,0.00,0.00,0,035.0.000.0.011.011,0,014.0.012.0,0.005.0.003.0.010.010.010.010.010,0.000.0.0.002.00.006, 0.009,0.029,0.000,0.039 ,0.002,0.016,0.034,0.114],[0.026,0.010,0.036,0.064,0.011,0.009,0.052,0.010,0.360,0.004,0.0.05,0.007,0.022,0.017 0.067,0.013,0.017,0.067,0.013,0.017,0.052,0.010,0.360 0.006,0.026,0.002,0.015,0.001,0.004,004,0.121,0.003,003,011,011,011,0.006,0.06,0.010.003,003,002,0.011111111111111111 0.032,0.023,0.009,0.022,0.012,0.064,0.031,0.026,0.010,0.019,0.007,0.034,0.004,0.021, 0.002,0.007,0.086,0.005,018,018,011,011,011,011,0.003,003,0.003,0.011] ,0.002,0.012,0.003,0.002,0.005,0.003] 0.000.0.096.0.00,0,095.0.00,0.004.0.003.0.013.010.012.045.0.006.0.017.0,013.010.002.0.016.0,0,029.0.00,0.00,0.00 ,0.00,0.360.0.023.0,045.0.023.0,023.0.005.0,018.0.008, 0.005,0.010,0.042,0.011,0.013,0.032,0.007]]
[[0.007,0.004,0.007,0.082,0.002,0.023,0.009,0.029,0.003,0.024,0.024,0.008,0.006,0.062,0.001,0.001,0.005,0.009,0.0,0.032,0.391,0.002 0.016,0.004,0.006 ,0.006,0.002,0.037,0.061,0.041,0.033,0.019,0.006],[0.004,0.004,0.008,0.078,0.001,0.013,0.005,0.0.06,0.059,0.0142,0.04 0.02,0.052,0.012,0.012,0.012,0.013 0.008,0.036,0.366,0.001,0.010,015,015,003,003,011,011,0.008,008,008,008,008,0.005,004,0.004,0.015,015,074.074,0.035,035,04.045,045,045,023 0.0.0.0.0.9.ch 0.0.0.0.0.9.com.0.0.9.comelly ,0.011.0.00.0.0.010.010.010,0.00,0.00,0,04,0,000.0,021.021.021.0,0,0,023.0,017.0.0.0.00,00,004,004,0.00.00,00,00,000.000.000.000.0.0.0.0.03.03.033.056.008,056.0.08.08,000.000.000.000.000.000.bast ,0.217],[0.021,0.011,0.02,02,0.060,0.018,018,0.026,0.090,090,0.014,014,0.234,0.005,005,05,019,019,019,011,011,011,025,025,011.011.011 011 0.011 0.052,00.052,00.052,0.00,0.00,00,0.00,0.0m,00,00,0c,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0,0les 0.016, 0.001, 0.003, 0.134, 0.006, 0.013, 0.011, 0.014, 0.004, 0.005, 0.020, 0.036, 0.26, 0.036, 0.027 0.020,0.053,0.018,0.269,0.006,0.008,0.029,0.036,0.007,0.029,0.021 ,0.046,0.030,0.028,0.009,0.023,0.007,0.027,0.003,0.020, 0.002,0.010,0.098,0.010,010.009,0.016,016,0.009,009,004,004,0.005,018] ,0.002,0.014,0.004,0.003,0.006,0.004] 0.000.0.186.0.004.0.107.0.005.0.00,0.003.0.010.010.0,041.0.00,0,017.0,018.0.001.03.0.030.014,012.0 .0.014.0.036.036.036,018.0.00,0.00,0,020.0 0.005,0.008,0.049,0.009,0.011,0.020,0.008]]
开始 = time.time()
KR887JJ 演唱:
打印(类别[sing.index(最大(唱))])
def list_mean(数字):
sumof, len = 0, 0
for i in nums:
sumof += i
#len += 1
return sumof / len
结束=time.time()
print(f"程序的运行时间是 {end - start}")
我尝试将我的 argmax 转换为 array.index(max(array)) 我将不胜感激任何帮助。 我需要加快我的代码。 此代码仅适用于一张图片,我将在一分钟内处理大约 20 张图片。所以这就是为什么我尝试让它尽可能快。
import time
import numpy as np
#tab = [0.061,0.001,0.022,0.002,0.015,0.021,0.066,0.005,0.053,0.018,0.011,0.024,0.052,0.021,0.077,0.010,0.045,0.017,0.016,0.007,0.071,0.167,0.052,0.016,0.017,0.004,0.009,0.014,0.001,0.059,0.018,0.008,0.004,0.009,0.009]#tabK = [0.009,0.003,0.002,0.001,0.157,0.003,0.067,0.005,0.006,0.002,0.012,0.005,0.033,0.002,0.007,0.010,0.001,0.008,0.037,0.008,0.377,0.011,0.043,0.009,0.004,0.002,0.013,0.016,0.004,0.005,0.057,0.013,0.023,0.026,0.018]CATEGORIES = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z"]
#KOLEJNOSC ZNAKOW W TABLICY JEST ODWROCONA
CATEGORIES = ["0","1","2","3","4","5","6","7","8","9",
"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","R","S","T","U",
"V","W","X","Y","Z"]
KR887JJ = [[0.002,0.006,0.004,0.045,0.002,0.017,0.006,0.077,0.001,0.035,0.042,0.005,0.004,0.039,0.001,0.002,0.001,0.008,0.058,0.352,0.002,0.007,0.017,0.004,0.007,0.007,0.007,0.004,0.005,0.009,0.089,0.036,0.053,0.041,0.004],[0.003,0.007,0.005,0.075,0.001,0.020,0.006,0.044,0.002,0.035,0.026,0.004,0.004,0.033,0.001,0.001,0.003,0.008,0.049,0.360,0.002,0.007,0.021,0.005,0.009,0.003,0.008,0.007,0.003,0.014,0.092,0.048,0.058,0.031,0.004],[0.002,0.000,0.025,0.012,0.006,0.002,0.001,0.627,0.006,0.021,0.022,0.008,0.004,0.006,0.004,0.033,0.000,0.006,0.011,0.009,0.002,0.002,0.009,0.000,0.002,0.040,0.007,0.005,0.015,0.000,0.035,0.001,0.008,0.015,0.053],[0.056,0.008,0.023,0.038,0.015,0.007,0.050,0.006,0.412,0.004,0.005,0.027,0.011,0.005,0.021,0.007,0.073,0.024,0.012,0.005,0.013,0.005,0.027,0.003,0.015,0.001,0.005,0.074,0.002,0.022,0.005,0.011,0.002,0.001,0.006],[0.025,0.011,0.025,0.034,0.018,0.027,0.090,0.008,0.258,0.006,0.007,0.026,0.016,0.008,0.026,0.011,0.079,0.030,0.026,0.008,0.018,0.011,0.033,0.003,0.016,0.001,0.003,0.106,0.004,0.021,0.012,0.013,0.003,0.005,0.014],[0.048,0.027,0.019,0.002,0.028,0.002,0.008,0.017,0.041,0.014,0.012,0.022,0.031,0.005,0.045,0.100,0.004,0.031,0.033,0.002,0.029,0.006,0.021,0.032,0.008,0.038,0.317,0.007,0.017,0.004,0.018,0.005,0.003,0.004,0.002],[0.013,0.002,0.002,0.000,0.164,0.001,0.060,0.004,0.006,0.002,0.018,0.003,0.035,0.002,0.008,0.008,0.001,0.008,0.028,0.005,0.383,0.013,0.063,0.010,0.004,0.002,0.014,0.016,0.002,0.005,0.048,0.011,0.028,0.017,0.012]]
[[0.004,0.007,0.005,0.042,0.002,0.014,0.011,0.054,0.002,0.032,0.051,0.005,0.005,0.044,0.001,0.002,0.002,0.008,0.056,0.389,0.003,0.008,0.023,0.005,0.009,0.005,0.009,0.006,0.004,0.010,0.070,0.029,0.049,0.031,0.005],[0.005,0.005,0.005,0.034,0.002,0.006,0.005,0.083,0.002,0.062,0.053,0.004,0.006,0.039,0.001,0.002,0.001,0.008,0.055,0.348,0.002,0.005,0.020,0.005,0.011,0.011,0.018,0.004,0.005,0.008,0.086,0.018,0.055,0.020,0.004],[0.001,0.001,0.024,0.009,0.013,0.003,0.002,0.499,0.006,0.011,0.022,0.011,0.007,0.006,0.006,0.048,0.000,0.008,0.013,0.009,0.004,0.002,0.007,0.000,0.002,0.053,0.009,0.007,0.030,0.000,0.030,0.001,0.009,0.021,0.123],[0.039,0.008,0.029,0.041,0.013,0.008,0.054,0.005,0.369,0.004,0.005,0.023,0.011,0.005,0.020,0.005,0.100,0.022,0.012,0.005,0.012,0.007,0.028,0.002,0.015,0.000,0.003,0.102,0.001,0.021,0.006,0.012,0.002,0.002,0.007],[0.031,0.007,0.018,0.032,0.015,0.017,0.075,0.008,0.365,0.005,0.005,0.028,0.015,0.005,0.022,0.011,0.075,0.027,0.014,0.005,0.020,0.006,0.025,0.002,0.014,0.001,0.004,0.099,0.003,0.016,0.008,0.009,0.002,0.002,0.010],[0.046,0.022,0.022,0.002,0.031,0.003,0.008,0.022,0.047,0.011,0.010,0.039,0.035,0.005,0.048,0.110,0.002,0.028,0.031,0.003,0.029,0.006,0.016,0.022,0.007,0.059,0.289,0.005,0.016,0.003,0.013,0.004,0.002,0.004,0.003],[0.019,0.004,0.002,0.000,0.134,0.004,0.088,0.006,0.004,0.003,0.016,0.007,0.037,0.004,0.016,0.014,0.002,0.014,0.026,0.005,0.342,0.019,0.049,0.024,0.004,0.003,0.021,0.009,0.005,0.009,0.049,0.012,0.017,0.026,0.006]]
[[0.002,0.005,0.005,0.046,0.002,0.014,0.008,0.073,0.002,0.023,0.042,0.004,0.007,0.027,0.001,0.003,0.001,0.006,0.047,0.384,0.005,0.006,0.015,0.003,0.006,0.004,0.011,0.006,0.006,0.005,0.088,0.027,0.066,0.040,0.010],[0.002,0.005,0.005,0.039,0.002,0.009,0.005,0.089,0.001,0.036,0.043,0.004,0.006,0.026,0.001,0.002,0.001,0.006,0.051,0.387,0.003,0.005,0.014,0.003,0.007,0.007,0.014,0.004,0.007,0.005,0.090,0.022,0.064,0.030,0.006],[0.002,0.001,0.014,0.011,0.020,0.005,0.004,0.282,0.005,0.012,0.022,0.011,0.009,0.010,0.008,0.041,0.000,0.017,0.030,0.019,0.009,0.003,0.009,0.000,0.004,0.053,0.010,0.016,0.049,0.000,0.043,0.002,0.017,0.037,0.224],[0.028,0.015,0.029,0.039,0.023,0.020,0.097,0.008,0.239,0.004,0.009,0.021,0.019,0.008,0.017,0.008,0.082,0.023,0.025,0.012,0.020,0.010,0.037,0.003,0.016,0.001,0.003,0.110,0.003,0.019,0.012,0.014,0.004,0.005,0.015],[0.037,0.013,0.035,0.053,0.025,0.022,0.057,0.017,0.250,0.005,0.009,0.037,0.025,0.008,0.029,0.013,0.057,0.029,0.029,0.009,0.015,0.009,0.027,0.002,0.020,0.002,0.006,0.092,0.006,0.012,0.011,0.011,0.003,0.004,0.021],[0.036,0.022,0.024,0.003,0.022,0.004,0.011,0.019,0.069,0.014,0.011,0.035,0.045,0.006,0.057,0.096,0.004,0.037,0.030,0.004,0.039,0.007,0.021,0.018,0.010,0.031,0.256,0.013,0.018,0.003,0.018,0.005,0.004,0.006,0.004],[0.015,0.003,0.002,0.000,0.174,0.004,0.085,0.008,0.005,0.002,0.015,0.008,0.028,0.003,0.013,0.016,0.001,0.015,0.029,0.004,0.357,0.013,0.043,0.017,0.003,0.003,0.017,0.010,0.004,0.007,0.037,0.013,0.015,0.020,0.010]]
[[0.005,0.006,0.006,0.055,0.002,0.017,0.009,0.076,0.003,0.035,0.032,0.007,0.005,0.050,0.001,0.002,0.002,0.011,0.050,0.391,0.002,0.005,0.018,0.003,0.012,0.009,0.009,0.005,0.005,0.012,0.068,0.032,0.032,0.017,0.006],[0.009,0.005,0.007,0.064,0.002,0.022,0.009,0.040,0.003,0.030,0.026,0.010,0.006,0.069,0.001,0.001,0.004,0.011,0.040,0.379,0.002,0.009,0.021,0.005,0.017,0.007,0.009,0.005,0.003,0.034,0.063,0.035,0.029,0.017,0.006],[0.001,0.001,0.014,0.011,0.011,0.004,0.003,0.458,0.004,0.012,0.023,0.010,0.007,0.009,0.006,0.039,0.000,0.012,0.016,0.014,0.005,0.003,0.007,0.000,0.002,0.052,0.008,0.009,0.039,0.000,0.036,0.001,0.013,0.032,0.139],[0.042,0.012,0.023,0.029,0.043,0.015,0.111,0.010,0.235,0.004,0.009,0.036,0.023,0.010,0.018,0.010,0.039,0.029,0.024,0.012,0.025,0.009,0.041,0.003,0.019,0.002,0.005,0.084,0.004,0.018,0.013,0.012,0.004,0.005,0.023],[0.030,0.008,0.017,0.033,0.011,0.020,0.103,0.009,0.289,0.004,0.006,0.030,0.022,0.007,0.021,0.011,0.108,0.031,0.013,0.008,0.020,0.006,0.023,0.002,0.018,0.001,0.004,0.102,0.005,0.012,0.007,0.007,0.002,0.003,0.009],[0.034,0.024,0.018,0.003,0.025,0.005,0.008,0.025,0.053,0.010,0.008,0.045,0.036,0.006,0.050,0.119,0.002,0.035,0.028,0.003,0.029,0.005,0.014,0.017,0.007,0.060,0.275,0.006,0.019,0.002,0.013,0.004,0.003,0.006,0.005],[0.016,0.004,0.002,0.000,0.130,0.003,0.080,0.005,0.004,0.003,0.017,0.005,0.038,0.002,0.015,0.014,0.002,0.011,0.027,0.004,0.378,0.016,0.051,0.019,0.004,0.002,0.020,0.012,0.004,0.006,0.040,0.013,0.023,0.020,0.008]]
[[0.006,0.004,0.007,0.052,0.002,0.012,0.005,0.066,0.002,0.043,0.036,0.007,0.007,0.051,0.001,0.001,0.002,0.008,0.037,0.401,0.002,0.008,0.017,0.004,0.013,0.010,0.014,0.004,0.004,0.016,0.077,0.021,0.038,0.018,0.006],[0.001,0.001,0.012,0.008,0.013,0.004,0.002,0.462,0.004,0.011,0.022,0.008,0.006,0.006,0.006,0.052,0.000,0.012,0.018,0.012,0.005,0.002,0.007,0.000,0.002,0.046,0.009,0.009,0.040,0.000,0.039,0.002,0.012,0.031,0.136],[0.004,0.003,0.007,0.042,0.001,0.008,0.005,0.060,0.002,0.062,0.050,0.005,0.004,0.053,0.000,0.001,0.002,0.006,0.033,0.422,0.001,0.008,0.017,0.004,0.011,0.007,0.010,0.003,0.002,0.013,0.065,0.024,0.045,0.017,0.003],[0.029,0.015,0.032,0.058,0.018,0.013,0.067,0.012,0.287,0.006,0.010,0.025,0.016,0.007,0.017,0.009,0.059,0.023,0.026,0.011,0.016,0.006,0.033,0.003,0.017,0.001,0.006,0.118,0.004,0.014,0.009,0.012,0.004,0.003,0.012],[0.056,0.011,0.024,0.034,0.027,0.015,0.065,0.013,0.271,0.006,0.007,0.062,0.028,0.013,0.026,0.014,0.030,0.039,0.027,0.011,0.019,0.006,0.031,0.003,0.027,0.005,0.009,0.061,0.006,0.014,0.011,0.006,0.002,0.004,0.016],[0.041,0.020,0.022,0.002,0.019,0.004,0.007,0.024,0.046,0.016,0.008,0.051,0.036,0.006,0.051,0.109,0.002,0.030,0.027,0.003,0.024,0.005,0.015,0.017,0.008,0.067,0.286,0.005,0.015,0.003,0.014,0.003,0.002,0.005,0.003],[0.014,0.003,0.002,0.000,0.106,0.007,0.079,0.007,0.004,0.003,0.014,0.010,0.041,0.004,0.013,0.011,0.001,0.014,0.031,0.007,0.377,0.022,0.049,0.017,0.004,0.003,0.014,0.009,0.004,0.009,0.050,0.013,0.016,0.034,0.008]]
[[0.008,0.004,0.008,0.064,0.001,0.018,0.009,0.041,0.003,0.043,0.035,0.008,0.005,0.076,0.001,0.001,0.004,0.009,0.037,0.382,0.001,0.011,0.024,0.005,0.015,0.006,0.007,0.005,0.002,0.030,0.057,0.031,0.029,0.017,0.004],[0.002,0.004,0.004,0.044,0.001,0.012,0.005,0.068,0.001,0.043,0.052,0.003,0.005,0.030,0.001,0.002,0.001,0.007,0.041,0.350,0.003,0.007,0.019,0.005,0.007,0.004,0.011,0.005,0.003,0.007,0.099,0.035,0.076,0.038,0.004],[0.001,0.001,0.015,0.011,0.009,0.004,0.002,0.517,0.004,0.012,0.028,0.007,0.005,0.007,0.005,0.035,0.000,0.011,0.014,0.012,0.005,0.003,0.010,0.000,0.002,0.030,0.006,0.009,0.029,0.000,0.039,0.002,0.016,0.034,0.114],[0.026,0.010,0.036,0.064,0.011,0.009,0.052,0.010,0.360,0.004,0.007,0.022,0.015,0.005,0.017,0.006,0.067,0.019,0.017,0.008,0.013,0.006,0.026,0.002,0.015,0.001,0.004,0.121,0.003,0.011,0.006,0.010,0.003,0.002,0.011],[0.044,0.017,0.027,0.037,0.024,0.016,0.079,0.010,0.259,0.006,0.009,0.032,0.023,0.009,0.022,0.012,0.064,0.031,0.026,0.010,0.019,0.007,0.034,0.004,0.021,0.002,0.007,0.086,0.005,0.018,0.011,0.011,0.003,0.003,0.011],[0.033,0.013,0.021,0.002,0.014,0.003,0.006,0.023,0.033,0.015,0.009,0.048,0.040,0.007,0.056,0.098,0.002,0.032,0.023,0.003,0.023,0.006,0.013,0.015,0.009,0.069,0.331,0.005,0.018,0.002,0.012,0.003,0.002,0.005,0.003],[0.017,0.004,0.002,0.000,0.096,0.008,0.095,0.007,0.004,0.003,0.013,0.012,0.045,0.006,0.017,0.013,0.002,0.016,0.029,0.007,0.360,0.023,0.045,0.023,0.005,0.004,0.018,0.008,0.005,0.010,0.042,0.011,0.013,0.032,0.007]]
[[0.007,0.004,0.007,0.082,0.002,0.023,0.009,0.029,0.003,0.024,0.024,0.008,0.006,0.062,0.001,0.001,0.005,0.009,0.032,0.391,0.002,0.012,0.020,0.005,0.016,0.004,0.006,0.006,0.002,0.037,0.061,0.041,0.033,0.019,0.006],[0.004,0.004,0.008,0.078,0.001,0.013,0.005,0.059,0.002,0.044,0.041,0.006,0.005,0.052,0.001,0.001,0.002,0.008,0.036,0.366,0.001,0.010,0.015,0.003,0.011,0.008,0.008,0.005,0.004,0.015,0.074,0.035,0.045,0.023,0.007],[0.001,0.001,0.013,0.010,0.015,0.006,0.004,0.299,0.004,0.011,0.021,0.011,0.009,0.010,0.009,0.044,0.000,0.021,0.023,0.017,0.008,0.004,0.007,0.000,0.003,0.056,0.008,0.014,0.056,0.000,0.040,0.002,0.016,0.039,0.217],[0.021,0.011,0.022,0.060,0.018,0.026,0.090,0.014,0.234,0.005,0.011,0.025,0.016,0.009,0.015,0.011,0.052,0.030,0.029,0.015,0.019,0.007,0.030,0.003,0.016,0.001,0.003,0.134,0.006,0.013,0.011,0.014,0.004,0.005,0.020],[0.031,0.012,0.027,0.036,0.023,0.020,0.053,0.018,0.269,0.006,0.008,0.029,0.036,0.007,0.029,0.021,0.046,0.030,0.028,0.009,0.023,0.007,0.027,0.003,0.020,0.002,0.010,0.098,0.010,0.009,0.016,0.009,0.004,0.005,0.018],[0.036,0.019,0.017,0.002,0.027,0.004,0.009,0.027,0.063,0.012,0.008,0.045,0.035,0.006,0.050,0.140,0.002,0.036,0.030,0.003,0.031,0.004,0.017,0.016,0.007,0.055,0.239,0.007,0.018,0.002,0.014,0.004,0.003,0.006,0.004],[0.018,0.004,0.002,0.000,0.186,0.004,0.107,0.005,0.005,0.003,0.010,0.008,0.041,0.004,0.017,0.018,0.001,0.012,0.034,0.004,0.300,0.014,0.036,0.018,0.004,0.004,0.020,0.010,0.005,0.008,0.049,0.009,0.011,0.020,0.008]]
start = time.time()
for sing in KR887JJ:
print(CATEGORIES[np.argmax(sing)])
#print(CATEGORIES[sing.index(max(sing))])
def list_mean(nums):
sumof = 0
num_of = len(nums)
mean = 0
for i in nums:
sumof += i
mean = sumof / num_of
return float(mean)
end = time.time()
print(f"Runtime of the program is {end - start}")
而且我 100% 需要这部分,因为我在 nums:
求和+=我。像这样的迭代不会占用大量内存,因为它一直在计数,而不是大块内存和平。
提前致谢!
np.argmax 并不比 array.index(np.max(array)) 慢,但是 list_mean 可以更有效率:如果你想要一个完整的 python实现,可以使用
sum(nums)/len(nums)
或者更高效:
np.mean(nums)
(您已经使用过数组)
或多或少: 导入时间 将 numpy 导入为 np
#数组中字符的顺序颠倒了 类别 = ["0","1","2","3","4","5","6","7","8","9","A","B" "C","D","E","F","G","H","I","J","K","L","M","N"," O","P","R","S","T","U","V","W","X","Y","Z"]
KR887JJ = [[0.002,0.006,0.004,0.045,0.002,0.017,0.006,0.077,0.001,0.035,0.042,0.005,0.004,0.039,0.001,0.002,0.052,0.001,0.0.0 0.052,0.001,0.0 ,0.017,0.004,0.007,0.007,0.007,0.004,0.005,0.009,0.089,0.036,0.053,0.041,0.004],[0.003,0.007,0.005,0.075,0.0.03,0.001,0.046,0.046,0.046,0.004] ,0.004 , 0.026.0.00,0.00,0.00,0,033.0.001.0.001.0.003.0.00,0,0,049.0.360.0.002.0.00,0.00,0,0,021.0.005.0.00,0.00,0.003.0.0.0,0,0,0 .0.00,0.00,0.003.0.014.0.092.092.0,092.0,048,0,058.0,031,0.004 ],[0.002,0.000,0.025,0.012,0.006,0.002,0.001,0.627,0.006.0.00421,0.0021,0.006.0.00221 ,0.006,0.004,0.033,0.000,0.006,0.0,0.020,0.009,0.020,0.009,0.020 ,0.002,0.040,0.007,0.005,0.015,0.000,0.035,0.001,0.008,0.056[0.056],0.008,0.056[] ,0.023,0.038,0.015,0.007,0.050.050.10.107,0.0.0.0206,0.412,0.412,006 0.005,021,021,007,007,073,073,024.024.024.012,012,0.0.0.13.0.bes0.0.0.bs-0.0.0.100,0.0.0.100,000.0.100,00s.0.bes。 0.022,0.005,0.011,0.002,0.061,0.025,0.034,0.018,018,0.027,027,0.090.090,0.008,008,0.258,0.6,006,006,007,007,026,026,016,0.0.88.8.8.8.8m.08.8.8m.08.8m,0.08.8.8m,0.0.8,008,000.08.cn, 00s.008,000.008,000.008,000.08.8.crel 0。 033,0.003,0.016,0.001,0.003,0.106,0.004,0.021,0.012,0.013,0.003,0.005,0.014],[0.048,0.027,0.019,0.002,0.028,0.002,0108,0.0035,0.0025,0.0025,0.0217 ,0.100,0.004,0.031,0.033,0.002,0.029,029,006,0.06,021,021,0.032,032,0.008,008,038,038,0.317,0.007,007,007,017,017,004,004,0055550.0.0.0.0.0.0.c.0050.0.c. 00. 00. 00. 00. 00. 00. 00. 00p0. 00p0.0.bay0.0C.0.0.it.0.0.its.0.0.0.it.0.0.0.it.0.0.0.bhis。 0.00,0,0.006.0.002.0.018.0.003.0,0,035.0,0,002.0.008.0.00,0.00,0.001,0,0.00,0.008.0,028.0.005.0 0.002,0.014,0.016,0.002,0.018185,0.002,0.01815 ,0.017,0.012]] [[0.004,0.007,0.005,0.042,0.002,0.014,0.011,0.054,0.002,0.032,0.051,0.005,0.005,0.044,0.001,0.002,0.002,0.008,0.03,0.056,0.389,0.003 0.009,0.005,0.009 ,0.006,0.004,0.010,0.070,0.029,0.049,0.031,0.005],[0.005,0.005,0.005,0.034,0.002,0.006,0.005,0.0.0.083,0.002,0.06 0.039,0.00101,0.002,0.002,0.06 0.055,0.348,0.002,0.005,020,020,005,005,011,011,011,018,018,0.018,0.004,0.005,005,008,008,0.086,086,018,018,0555,055,04.040.040 0.040 0.0.0.0.00,000.000.00,000.000.00,000. 000.000.bas 0.001,0.009,0.021,0.123],[0.039,0.008,0.0.029,029,041,041,0.013,013,0.008,008,0.054,0.005,005,005,0.369,0.36,0.0.4,05,05,005,0.0.0.13,0.0.13,0.0.b,0.13,0.0.13,0.0.13,0.0.13,00.0.bhist ,0.002,0.015,0.000,0.003,0.102,0.001,0.021,0.006,0.012,0.002,0.002,0.007,0.0.017,0.075,0.008,0.365,0.005,0.005,0.028,0.01.015,0.028,0.01.015,0.028,0.01.015,0 ,0.027,0.014,0.005,0.020,0.006,0.025,0.002,0.014, 0.001,0.004,0.099,0.003,016,016,0.008,009,009,009,002,002,002,0.010] ,0.028,0.031,0.003,0.029,0.006,0.016,0.022,0.007,0.059,0.289,0.005,0.016,0.003,0.013,0.004,0.002,0.004,0.003] 0.000.0.134.0.00,0,088,0.006.0.00,0.003 .0.016.0,016.0,037.0.00,0,016.0,014.0.002.0.014.0.026.026.026,0.005.0.342.0.019.0.049.0,0,024.0.00,0.003.0.021,0,021,0.0109,0.0109,0.0109,0.0109,0.0109 ,0.017,0.026,0.006]] [[0.002,0.005,0.005,0.046,0.002,0.014,0.008,0.073,0.002,0.023,0.042,0.004,0.007,0.027,0.001,0.003,0.001,0.006,0.03,0.047,0.384,0.005 0.006,0.004,0.011 ,0.006,0.006,0.005,0.088,0.027,0.066,0.040,0.010]. 0.026,0.001,0.002,0.001,0.006,0.051,0.387,0.003,0.005,0.014,0.003,0.07,0.007,0.014,0.014,0.014,0.014 0.005,0.090,0.022,0.064,0.030 0.014.0.011.0,020,0.00,0.00,0.00,0.282.0.005.0.012.022,0.011,0.00.0.010.010.010,0.00,0,040.0.037.010 ,0.00,0.003.0.00,0.0,000.0 0.016,0.049,0.000,0.043,0.002,0.017,0.037,0.224]. 0.082,0.023,0.025,0.012,0.020,0.010,0.037,01.0.0103,0.00163,0.037,01.001063,0.0163,0 ,0.003,0.019,0.012,0.014,0.004,0.005,0.037,0.5,0.0.022,0.057,0.017,0.250,0.005,0.009,0.037,0.025,0.008,0.029,0.013,0.019,0.059,0.027,0.027,0.029 ,0.009,0.027,0.002,0.020, 0.002,0.006,0.092,0.006,0.012,012,011,011,011,011,0.003,004.004,0.021] ,0.003,0.018,0.005,0.035,0.006,0.004] 0.000.0.174.0.00,0,085.0.00,0.005.0.002.0,015.0.00,0,028.0.003.0.013.0,016.0,0,000.0,0,05.09.0,02.01 ,0.357.0.019.013.0.043.0,0,017,0.003.0.003.0.017.0.010, 0.004,0.007,0.037,0.013,0.015,0.020,0.010]] [[0.005,0.006,0.006,0.055,0.002,0.017,0.009,0.076,0.003,0.035,0.032,0.007,0.005,0.050,0.001,0.002,0.002,0.011,0.0.050,0.0120,0.0120,0.0120,0.0121,0.011,0.0.050,0.0120,0.0120 ,0.005,0.005,0.012,0.068,0.032,0.032,0.017,0.006],[0.009,0.005,0.007,0.064,0.002,0.022,0.009,0.0,0,0.040,0.003,0.03 0.069,0.04,0.000 0.011,0.040,0.379,0.002,009,009,0.021,021,0.005,017,017,0.007,007,0.009,009,009,005,005,003,003,0.034.063,063,0.03,035,029.029.0.0.9.ctel .010.0.00,0.00,0,0,0,0,039.0.000.0.012.0.016.0,016.014,0.005.0.003.0.00,0.00,0.000.0.002.0.052.0008, 0.009,0.039,0.000.0.0136,0.036, ,0.032,0.139]. 0.039,0.029,0.024,0.012,0.025,0.009,0.041,0.003,0.019,0.002,0.005,0.084,0.004,0.018,0.013,0.012,0.004,0,01,0.012,0.012,0.012,0.012,0.004,0.01,0.012,0.012 018 0.020,0.103,0.009,0.289,0.004,0.006,0.030,0.022,0.007,0.021,0.011,0.108,0.031,0.013,0.008,0.020,0.006,0.023,0.002,0.018, 0.001,0.004,0.102,0.005,012,012,0.007,007,007,007,002,002,0.003,0.009] ,0.002,0.013,0.004,0.003,0.006,0.005] 0.000.0.130.0.003.0.080.0,0.00,0.00,0.003.0.017.0,0,038.0,0,002.0.015.0.014.0.002.0.0.02711 0.004,0.006,0.040,0.013,0.023,0.020,0.008]] [[0.006,0.004,0.007,0.052,0.002,0.012,0.005,0.066,0.002,0.043,0.036,0.007,0.007,0.051,0.001,0.001,0.002,0.008,0.0.037,0.01301,0.01301,0.01301,0.008,0.0.037,0.01301,0.0102 ,0.004,0.004,0.016,0.077,0.021,0.038,0.018,0.006],[0.001,0.001,0.012,0.008,0.013,0.004,0.002,0.08,0.06,0.022,0.014,0.012,0.056,0.02,0.066 0.012,0.018,0.012,0.005,005,002,002,007,007,0.000.000.002,002,04.046,0.009,009,009,009,009,0.040.000.000.000.000.000.039,039,002,002,002,012,012,0.0.00.0.00.00.00.00.00.ly. 00. 00. 00. 00. 00. 00. 00. 00p0. 00p. 00,000.00p0.w.ars.0.去不从而.050,0.00,0,053.0.0.000,0.001.0.002.0.006.0.033,0,033,0 0.003,0.002,0.013,0.065,0.024,0.045,0.017,0.003],[0.029,0.015,0.0138,0.0580,0.0580,0.029 0.067,0.012,0.287,0.006,0.09,0.010,0.025,0.017,0.010,0.025,0.017 0.059,0.023,0.026,0.011,0.016,0.006,0.033,0.003,0.017,0.001,0.006,0.118,0.004,0.014,0.009 ,0.012,0.004,0.003,0.012],[0.056,0.024] 0.015,0.065,0.013,0.271,0.006,0.007,0.062,0.028,0.013,0.026,0.014,0.030,0.039,0.0160,0.0127,0.030,0.039,0.0160,0.0127 ,0.003,0.027, 0.005,0.009,0.061,0.006,0.014,0.011,0.006,0.002,0.004,0.016],[0.041,0.020,0.022,0.002,0.019,0.004,0.007,0.024,0.0.36,0.016,0.016,0.016,0.019,0.024,0.0.36,0.016,0.016,0.019 ,0.002,0.030,0.027,0.003,0.024,0.005,0.015,0.017,0.008,0.067,0.286,0.005,0.015,0.003,0.014,0.003,0.002,0.005,0.003 0.000.0.106.0.00,0,079.0.00,0.004. 0.003.0.014.0.010.041.0.00,0.013.010.011,0.001.0,014.0.031,0.007.0 0.004,0.009,0.050,0.013,0.016,0.034,0.008]] [[0.008,0.004,0.008,0.064,0.001,0.018,0.009,0.041,0.003,0.043,0.035,0.008,0.005,0.076,0.001,0.001,0.004,0.009,0.0.037,0.0160,0.037,0.0182,0.0182,0.015 ,0.005,0.002,0.030,0.057,0.031,0.029,0.017,0.004],[0.002,0.004,0.004,0.044,0.001,0.012,0.005,0.32,0.068,0.001,0.04 0,030,0.07,0.012 0.041,0.350,0.003,007,007,019,0.005,005,007,007,0.004,004,0.011,011,0.005,005,003,003,007,007,099999,0.035,035,076,076,0.048 0.048 0.0.0.0.0.0.0.bes.0.0.bes.0.0.bes.0.0.bes.0.000.00.0.00 n.0.00,000.00.0.,00s.0,000.00.0.bes ,0.005.0.00,0.00,0.00,0.00,0.00,0.00,0,035.0.000.0.011.011,0,014.0.012.0,0.005.0.003.0.010.010.010.010.010,0.000.0.0.002.00.006, 0.009,0.029,0.000,0.039 ,0.002,0.016,0.034,0.114],[0.026,0.010,0.036,0.064,0.011,0.009,0.052,0.010,0.360,0.004,0.0.05,0.007,0.022,0.017 0.067,0.013,0.017,0.067,0.013,0.017,0.052,0.010,0.360 0.006,0.026,0.002,0.015,0.001,0.004,004,0.121,0.003,003,011,011,011,0.006,0.06,0.010.003,003,002,0.011111111111111111 0.032,0.023,0.009,0.022,0.012,0.064,0.031,0.026,0.010,0.019,0.007,0.034,0.004,0.021, 0.002,0.007,0.086,0.005,018,018,011,011,011,011,0.003,003,0.003,0.011] ,0.002,0.012,0.003,0.002,0.005,0.003] 0.000.0.096.0.00,0,095.0.00,0.004.0.003.0.013.010.012.045.0.006.0.017.0,013.010.002.0.016.0,0,029.0.00,0.00,0.00 ,0.00,0.360.0.023.0,045.0.023.0,023.0.005.0,018.0.008, 0.005,0.010,0.042,0.011,0.013,0.032,0.007]] [[0.007,0.004,0.007,0.082,0.002,0.023,0.009,0.029,0.003,0.024,0.024,0.008,0.006,0.062,0.001,0.001,0.005,0.009,0.0,0.032,0.391,0.002 0.016,0.004,0.006 ,0.006,0.002,0.037,0.061,0.041,0.033,0.019,0.006],[0.004,0.004,0.008,0.078,0.001,0.013,0.005,0.0.06,0.059,0.0142,0.04 0.02,0.052,0.012,0.012,0.012,0.013 0.008,0.036,0.366,0.001,0.010,015,015,003,003,011,011,0.008,008,008,008,008,0.005,004,0.004,0.015,015,074.074,0.035,035,04.045,045,045,023 0.0.0.0.0.9.ch 0.0.0.0.0.9.com.0.0.9.comelly ,0.011.0.00.0.0.010.010.010,0.00,0.00,0,04,0,000.0,021.021.021.0,0,0,023.0,017.0.0.0.00,00,004,004,0.00.00,00,00,000.000.000.000.0.0.0.0.03.03.033.056.008,056.0.08.08,000.000.000.000.000.000.bast ,0.217],[0.021,0.011,0.02,02,0.060,0.018,018,0.026,0.090,090,0.014,014,0.234,0.005,005,05,019,019,019,011,011,011,025,025,011.011.011 011 0.011 0.052,00.052,00.052,0.00,0.00,00,0.00,0.0m,00,00,0c,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0.0m,00,00,0,0les 0.016, 0.001, 0.003, 0.134, 0.006, 0.013, 0.011, 0.014, 0.004, 0.005, 0.020, 0.036, 0.26, 0.036, 0.027 0.020,0.053,0.018,0.269,0.006,0.008,0.029,0.036,0.007,0.029,0.021 ,0.046,0.030,0.028,0.009,0.023,0.007,0.027,0.003,0.020, 0.002,0.010,0.098,0.010,010.009,0.016,016,0.009,009,004,004,0.005,018] ,0.002,0.014,0.004,0.003,0.006,0.004] 0.000.0.186.0.004.0.107.0.005.0.00,0.003.0.010.010.0,041.0.00,0,017.0,018.0.001.03.0.030.014,012.0 .0.014.0.036.036.036,018.0.00,0.00,0,020.0 0.005,0.008,0.049,0.009,0.011,0.020,0.008]]
开始 = time.time()
KR887JJ 演唱: 打印(类别[sing.index(最大(唱))])
def list_mean(数字):
sumof, len = 0, 0
for i in nums:
sumof += i
#len += 1
return sumof / len
结束=time.time()
print(f"程序的运行时间是 {end - start}")