- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 32x32 的 float 矩阵。我想得到其中所有元素的总和。但是当我使用循环时:
s = 0
for i in range(len(Temp)):
for j in range(len(Temp)):
s += Temp[i][j]
我得到 2.795541576006144e-13
当我使用 NumPy .sum(..)
方法时:
np.sum(Temp)
我得到 3.197442310920451e-13
结果截然不同,到底哪个是对的?
附言无法显示我在上面的示例中使用的数组,因为它说我的帖子主要是代码
[ 1.46992605 -4.38174259 7.11556386 -9.63811941 11.89561903
-13.57161385 14.72605916 -15.41213544 15.31459028 -14.72605916
13.65805725 -12.19869213 10.13557074 -7.67002338 4.8085357
-1.64285853 -1.66207325 4.89389432 -7.94725314 10.81956631
-13.33521624 15.38692526 -16.97717649 18.43603543 -17.16794834
16.69578682 -16.16491586 14.16866725 -11.81446896 8.6865325
-5.51985755 1.90225724]
[ -4.35328971 12.97683985 -21.07324444 28.54397071 -35.22971513
40.19329204 -43.61226329 45.6441266 -45.35523972 43.61226329
-40.44930027 36.12728748 -30.01720791 22.71531543 -14.24081776
4.86544144 4.92234719 -14.49361334 23.53635093 -32.04290906
39.49318383 -45.56946487 50.27910609 -54.59961979 50.84409039
-49.44575074 47.87353893 -41.96150782 34.98938345 -25.72577893
16.34744761 -5.63366904]
[ 7.0693589 -21.07324444 34.22109206 -46.35289322 57.20995302
-65.27036457 70.8224726 -74.12203957 73.65291273 -70.8224726
65.68609937 -58.66753144 48.74530062 -36.88767066 23.12583318
-7.90104818 -7.9934581 23.53635093 -38.22095996 52.03486078
-64.13345052 74.00079549 -81.64883784 88.66497138 -82.56632255
80.29554219 -77.74240875 68.14179118 -56.81967556 41.7763981
-26.54681442 9.1485821 ]
[ -9.51375658 28.35981606 -46.0538423 62.38050004 -76.99164451
87.83913358 -95.31101401 99.75148412 -99.12014562 95.31101401
-88.39861851 78.95321507 -65.60013876 49.64245339 -31.12213581
10.63302206 10.75738489 -31.67459976 51.43675893 -70.02714198
86.30910468 -99.58831705 109.88085054 -119.32297784 111.11557725
-108.05962098 104.6236814 -91.70342372 76.46641941 -56.22157372
35.72600205 -12.31192028]
[ 11.59254593 -34.55653586 56.11676921 -76.01085923 93.81459028
-107.03229395 116.13680659 -121.54753509 120.77824689 -116.13680659
107.71402831 -96.20477092 79.93400035 -60.48950447 37.9224322
-12.95637487 -13.10791142 38.59561147 -62.6758721 85.3283194
-105.16794834 121.34871544 -133.89020378 145.39546918 -135.39472263
131.67102913 -127.48432464 111.74094511 -93.17460164 68.50618579
-43.53225945 15.00211827]
[ -13.22584025 39.42526736 -64.02316015 86.72016373 -107.03229395
122.11226329 -132.49952683 138.67258244 -137.79490787 132.49952683
-122.89004841 109.75923138 -91.19604314 69.01197782 -43.2653908
14.78182146 14.95470826 -44.03341549 71.50638666 -97.35037734
119.98524672 -138.44575074 152.75423157 -165.88049418 154.47072474
-150.22239348 145.44581679 -127.48432464 106.30213618 -78.15814356
49.66559654 -17.11579326]
[ 14.35087294 -42.77890794 69.46917695 -94.09686096 116.13680659
-132.49952683 143.77036457 -150.46852022 149.51618781 -143.77036457
133.34347287 -119.09570613 98.95347314 -74.88235957 46.94568469
-16.03921093 -16.22680405 47.77904004 -77.58895088 105.63131489
-130.19157937 150.22239348 -165.74799991 179.99082482 -167.61050354
163.00079549 -157.81790776 138.32855308 -115.34453924 84.8065277
-53.8903126 18.57171792]
[ -14.92440963 44.48857909 -72.24553223 97.8574686 -120.77824689
137.79490787 -149.51618781 156.48203715 -155.49164451 149.51618781
-138.67258244 123.85539968 -102.90817666 77.87505423 -48.82188225
16.68022253 16.87531285 -49.68854288 80.68981522 -109.85290024
135.39472263 -156.22607389 172.37216557 -187.184209 174.30910468
-169.51516835 164.12514504 -143.85689279 119.95431635 -88.19584455
56.04405417 -19.31394188]
[ 14.92440963 -44.48857909 72.24553223 -97.8574686 120.77824689
-137.79490787 149.51618781 -156.48203715 155.49164451 -149.51618781
138.67258244 -123.85539968 102.90817666 -77.87505423 48.82188225
-16.68022253 -16.87531285 49.68854288 -80.68981522 109.85290024
-135.39472263 156.22607389 -172.37216557 187.184209 -174.30910468
169.51516835 -164.12514504 143.85689279 -119.95431635 88.19584455
-56.04405417 19.31394188]
[ -14.35087294 42.77890794 -69.46917695 94.09686096 -116.13680659
132.49952683 -143.77036457 150.46852022 -149.51618781 143.77036457
-133.34347287 119.09570613 -98.95347314 74.88235957 -46.94568469
16.03921093 16.22680405 -47.77904004 77.58895088 -105.63131489
130.19157937 -150.22239348 165.74799991 -179.99082482 167.61050354
-163.00079549 157.81790776 -138.32855308 115.34453924 -84.8065277
53.8903126 -18.57171792]
[ 13.22584025 -39.42526736 64.02316015 -86.72016373 107.03229395
-122.11226329 132.49952683 -138.67258244 137.79490787 -132.49952683
122.89004841 -109.75923138 91.19604314 -69.01197782 43.2653908
-14.78182146 -14.95470826 44.03341549 -71.50638666 97.35037734
-119.98524672 138.44575074 -152.75423157 165.88049418 -154.47072474
150.22239348 -145.44581679 127.48432464 -106.30213618 78.15814356
-49.66559654 17.11579326]
[ -11.59254593 34.55653586 -56.11676921 76.01085923 -93.81459028
107.03229395 -116.13680659 121.54753509 -120.77824689 116.13680659
-107.71402831 96.20477092 -79.93400035 60.48950447 -37.9224322
12.95637487 13.10791142 -38.59561147 62.6758721 -85.3283194
105.16794834 -121.34871544 133.89020378 -145.39546918 135.39472263
-131.67102913 127.48432464 -111.74094511 93.17460164 -68.50618579
43.53225945 -15.00211827]
[ 9.51375658 -28.35981606 46.0538423 -62.38050004 76.99164451
-87.83913358 95.31101401 -99.75148412 99.12014562 -95.31101401
88.39861851 -78.95321507 65.60013876 -49.64245339 31.12213581
-10.63302206 -10.75738489 31.67459976 -51.43675893 70.02714198
-86.30910468 99.58831705 -109.88085054 119.32297784 -111.11557725
108.05962098 -104.6236814 91.70342372 -76.46641941 56.22157372
-35.72600205 12.31192028]
[ -7.0693589 21.07324444 -34.22109206 46.35289322 -57.20995302
65.27036457 -70.8224726 74.12203957 -73.65291273 70.8224726
-65.68609937 58.66753144 -48.74530062 36.88767066 -23.12583318
7.90104818 7.9934581 -23.53635093 38.22095996 -52.03486078
64.13345052 -74.00079549 81.64883784 -88.66497138 82.56632255
-80.29554219 77.74240875 -68.14179118 56.81967556 -41.7763981
26.54681442 -9.1485821 ]
[ 4.35328971 -12.97683985 21.07324444 -28.54397071 35.22971513
-40.19329204 43.61226329 -45.6441266 45.35523972 -43.61226329
40.44930027 -36.12728748 30.01720791 -22.71531543 14.24081776
-4.86544144 -4.92234719 14.49361334 -23.53635093 32.04290906
-39.49318383 45.56946487 -50.27910609 54.59961979 -50.84409039
49.44575074 -47.87353893 41.96150782 -34.98938345 25.72577893
-16.34744761 5.63366904]
[ -1.46992605 4.38174259 -7.11556386 9.63811941 -11.89561903
13.57161385 -14.72605916 15.41213544 -15.31459028 14.72605916
-13.65805725 12.19869213 -10.13557074 7.67002338 -4.8085357
1.64285853 1.66207325 -4.89389432 7.94725314 -10.81956631
13.33521624 -15.38692526 16.97717649 -18.43603543 17.16794834
-16.69578682 16.16491586 -14.16866725 11.81446896 -8.6865325
5.51985755 -1.90225724]
[ -1.46992605 4.38174259 -7.11556386 9.63811941 -11.89561903
13.57161385 -14.72605916 15.41213544 -15.31459028 14.72605916
-13.65805725 12.19869213 -10.13557074 7.67002338 -4.8085357
1.64285853 1.66207325 -4.89389432 7.94725314 -10.81956631
13.33521624 -15.38692526 16.97717649 -18.43603543 17.16794834
-16.69578682 16.16491586 -14.16866725 11.81446896 -8.6865325
5.51985755 -1.90225724]
[ 4.35328971 -12.97683985 21.07324444 -28.54397071 35.22971513
-40.19329204 43.61226329 -45.6441266 45.35523972 -43.61226329
40.44930027 -36.12728748 30.01720791 -22.71531543 14.24081776
-4.86544144 -4.92234719 14.49361334 -23.53635093 32.04290906
-39.49318383 45.56946487 -50.27910609 54.59961979 -50.84409039
49.44575074 -47.87353893 41.96150782 -34.98938345 25.72577893
-16.34744761 5.63366904]
[ -7.0693589 21.07324444 -34.22109206 46.35289322 -57.20995302
65.27036457 -70.8224726 74.12203957 -73.65291273 70.8224726
-65.68609937 58.66753144 -48.74530062 36.88767066 -23.12583318
7.90104818 7.9934581 -23.53635093 38.22095996 -52.03486078
64.13345052 -74.00079549 81.64883784 -88.66497138 82.56632255
-80.29554219 77.74240875 -68.14179118 56.81967556 -41.7763981
26.54681442 -9.1485821 ]
[ 9.51375658 -28.35981606 46.0538423 -62.38050004 76.99164451
-87.83913358 95.31101401 -99.75148412 99.12014562 -95.31101401
88.39861851 -78.95321507 65.60013876 -49.64245339 31.12213581
-10.63302206 -10.75738489 31.67459976 -51.43675893 70.02714198
-86.30910468 99.58831705 -109.88085054 119.32297784 -111.11557725
108.05962098 -104.6236814 91.70342372 -76.46641941 56.22157372
-35.72600205 12.31192028]
[ -11.59254593 34.55653586 -56.11676921 76.01085923 -93.81459028
107.03229395 -116.13680659 121.54753509 -120.77824689 116.13680659
-107.71402831 96.20477092 -79.93400035 60.48950447 -37.9224322
12.95637487 13.10791142 -38.59561147 62.6758721 -85.3283194
105.16794834 -121.34871544 133.89020378 -145.39546918 135.39472263
-131.67102913 127.48432464 -111.74094511 93.17460164 -68.50618579
43.53225945 -15.00211827]
[ 13.22584025 -39.42526736 64.02316015 -86.72016373 107.03229395
-122.11226329 132.49952683 -138.67258244 137.79490787 -132.49952683
122.89004841 -109.75923138 91.19604314 -69.01197782 43.2653908
-14.78182146 -14.95470826 44.03341549 -71.50638666 97.35037734
-119.98524672 138.44575074 -152.75423157 165.88049418 -154.47072474
150.22239348 -145.44581679 127.48432464 -106.30213618 78.15814356
-49.66559654 17.11579326]
[ -14.35087294 42.77890794 -69.46917695 94.09686096 -116.13680659
132.49952683 -143.77036457 150.46852022 -149.51618781 143.77036457
-133.34347287 119.09570613 -98.95347314 74.88235957 -46.94568469
16.03921093 16.22680405 -47.77904004 77.58895088 -105.63131489
130.19157937 -150.22239348 165.74799991 -179.99082482 167.61050354
-163.00079549 157.81790776 -138.32855308 115.34453924 -84.8065277
53.8903126 -18.57171792]
[ 14.92440963 -44.48857909 72.24553223 -97.8574686 120.77824689
-137.79490787 149.51618781 -156.48203715 155.49164451 -149.51618781
138.67258244 -123.85539968 102.90817666 -77.87505423 48.82188225
-16.68022253 -16.87531285 49.68854288 -80.68981522 109.85290024
-135.39472263 156.22607389 -172.37216557 187.184209 -174.30910468
169.51516835 -164.12514504 143.85689279 -119.95431635 88.19584455
-56.04405417 19.31394188]
[ -14.92440963 44.48857909 -72.24553223 97.8574686 -120.77824689
137.79490787 -149.51618781 156.48203715 -155.49164451 149.51618781
-138.67258244 123.85539968 -102.90817666 77.87505423 -48.82188225
16.68022253 16.87531285 -49.68854288 80.68981522 -109.85290024
135.39472263 -156.22607389 172.37216557 -187.184209 174.30910468
-169.51516835 164.12514504 -143.85689279 119.95431635 -88.19584455
56.04405417 -19.31394188]
[ 14.35087294 -42.77890794 69.46917695 -94.09686096 116.13680659
-132.49952683 143.77036457 -150.46852022 149.51618781 -143.77036457
133.34347287 -119.09570613 98.95347314 -74.88235957 46.94568469
-16.03921093 -16.22680405 47.77904004 -77.58895088 105.63131489
-130.19157937 150.22239348 -165.74799991 179.99082482 -167.61050354
163.00079549 -157.81790776 138.32855308 -115.34453924 84.8065277
-53.8903126 18.57171792]
[ -13.22584025 39.42526736 -64.02316015 86.72016373 -107.03229395
122.11226329 -132.49952683 138.67258244 -137.79490787 132.49952683
-122.89004841 109.75923138 -91.19604314 69.01197782 -43.2653908
14.78182146 14.95470826 -44.03341549 71.50638666 -97.35037734
119.98524672 -138.44575074 152.75423157 -165.88049418 154.47072474
-150.22239348 145.44581679 -127.48432464 106.30213618 -78.15814356
49.66559654 -17.11579326]
[ 11.59254593 -34.55653586 56.11676921 -76.01085923 93.81459028
-107.03229395 116.13680659 -121.54753509 120.77824689 -116.13680659
107.71402831 -96.20477092 79.93400035 -60.48950447 37.9224322
-12.95637487 -13.10791142 38.59561147 -62.6758721 85.3283194
-105.16794834 121.34871544 -133.89020378 145.39546918 -135.39472263
131.67102913 -127.48432464 111.74094511 -93.17460164 68.50618579
-43.53225945 15.00211827]
[ -9.51375658 28.35981606 -46.0538423 62.38050004 -76.99164451
87.83913358 -95.31101401 99.75148412 -99.12014562 95.31101401
-88.39861851 78.95321507 -65.60013876 49.64245339 -31.12213581
10.63302206 10.75738489 -31.67459976 51.43675893 -70.02714198
86.30910468 -99.58831705 109.88085054 -119.32297784 111.11557725
-108.05962098 104.6236814 -91.70342372 76.46641941 -56.22157372
35.72600205 -12.31192028]
[ 7.0693589 -21.07324444 34.22109206 -46.35289322 57.20995302
-65.27036457 70.8224726 -74.12203957 73.65291273 -70.8224726
65.68609937 -58.66753144 48.74530062 -36.88767066 23.12583318
-7.90104818 -7.9934581 23.53635093 -38.22095996 52.03486078
-64.13345052 74.00079549 -81.64883784 88.66497138 -82.56632255
80.29554219 -77.74240875 68.14179118 -56.81967556 41.7763981
-26.54681442 9.1485821 ]
[ -4.35328971 12.97683985 -21.07324444 28.54397071 -35.22971513
40.19329204 -43.61226329 45.6441266 -45.35523972 43.61226329
-40.44930027 36.12728748 -30.01720791 22.71531543 -14.24081776
4.86544144 4.92234719 -14.49361334 23.53635093 -32.04290906
39.49318383 -45.56946487 50.27910609 -54.59961979 50.84409039
-49.44575074 47.87353893 -41.96150782 34.98938345 -25.72577893
16.34744761 -5.63366904]
[ 1.46992605 -4.38174259 7.11556386 -9.63811941 11.89561903
-13.57161385 14.72605916 -15.41213544 15.31459028 -14.72605916
13.65805725 -12.19869213 10.13557074 -7.67002338 4.8085357
-1.64285853 -1.66207325 4.89389432 -7.94725314 10.81956631
-13.33521624 15.38692526 -16.97717649 18.43603543 -17.16794834
16.69578682 -16.16491586 14.16866725 -11.81446896 8.6865325
-5.51985755 1.90225724]
最佳答案
他们都是对的。请注意,它是如此之小,以至于在这两种情况下它几乎为零(因为 e-13 部分)。
请参阅这篇关于浮点运算问题和限制的帖子:https://docs.python.org/3/tutorial/floatingpoint.html
关于python - 二维数组中所有元素的总和,不同的方法 - 不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51820019/
我基本上有三个表: hunt_c_usershunt_c_collected_eggshunt_c_achievements 我目前只使用 hunt_c_users 和 hunt_c_collecte
我已经计算了不同表中计数的总和。这会执行两次,每个 performanceID 一次。现在我想得到两个总和的总和。 下面是我目前做的两个总和的代码: SELECT SUM((COUNT (Bo
我有一个对 2 个值求和的脚本。我计划添加更多值(value),但首先我需要让它发挥作用。人们告诉我给他们 NUMBER 值,所以我这样做了,但现在它甚至没有给出输出。 base = 0; $("#F
我正在尝试计算在我们的数据库中跟踪的花费总额。每个订单文档包含一个字段“total_price” 我正在尝试使用以下代码: db.orders.aggregate({ $group: {
给定 Excel 2013(或更高版本)中的 2 个命名表: tbl发票 ID InvRef Total 1 I/123 45 2 I/234
希望你们一切都好。我来这里是因为我从今天早上开始就试图解决一个问题,我再也受不了了。 这就是上下文:我有一个 excel 工作簿,其中有不同的工作表,其中包含不同国家/地区的不同商业计划。我的目标是制
我有一份报告显示客户订购的产品及其价格: CompanyA Product 7 14.99 CompanyA Product 3 45.95 CompanyA Prod
我使用此python客户端: https://github.com/ryananguiano/python-redis-timeseries 如何汇总所有匹配? ts = TimeSeries(cli
希望创建一个总和和计数公式,该公式将自动调整以适应范围内插入的新行。 例如,如果我在单元格 D55 中有公式 =SUM(D17:D54)。每次我在该范围内插入新行时,我都需要更改公式的顶部范围来解释它
所以,我需要聚合日期相同的行。 到目前为止,我的代码返回以下内容: date value source 0 2018-04-08 15:52:26.1
我有数字输入 数量约为 30 我需要将它们全部汇总到一个字段 我拥有的在下面 查看:
您好,我正在尝试根据以下数据计算过去三个月中出现不止一次的不同帐户 ID 的数量;我想要 2 作为查询结果,因为 test1@gmail.com 和 test2@gmail.com 出现超过 1 次。
我有两个带有以下字段的表: ... orders.orderID orders.orderValue 和 payments.orderID payments.payVal 在 payments.pay
我想按 image_gallery 和 video_gallery 两列的 DESC 进行排序。 SELECT b.*, c.title as category, (S
实际上我的原始数据库为 SELECT sum(data1,data2) as database_value,sum(data3,data4) as database_not_value from t
我试图获取三个分数中每一个的值并将它们相加并显示在“总计:”中。我的问题是,我不知道如何做到这一点,以便每次其中一个分数值发生变化时,相应的总分值也会随之变化。 我可以在某处调用“onchange”来
如何获得按第一个值分组的元组列表中第二个和第三个值的总和? 即: list_of_tuples = [(1, 3, 1), (1, 2, 4), (2, 1, 0), (2, 2, 0)] expec
我正在尝试将我的列表中的整数转换为列表的总和和平均值,并说明任何低于冰点 F<32 的温度。每当我尝试获取总和或平均值时,我都会收到错误提示“+: 'int' 和 'str' 不支持的操作数类型”。我
在我的 ios 项目中,我使用了两个实体 (CoreData):具有一对多关系的 Person 和 Gifts 我知道如何计算给一个人的礼物总和: NSDecimalNumber *orderSum=
我有两个表(输入和类别): CREATE TABLE categories ( iId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sNam
我是一名优秀的程序员,十分优秀!