[英]Multiplying of two different sizes of DataFrame
這是一個荒謬的問題,值得一個荒謬的答案! (通常我同意@piRSquared)
import numpy as np
ini_pop = np.random.rand(10, 6)
Existing_Value = np.random.rand(149, 6)
Existing_Value = np.where(Existing_Value > .5, 1, 0)
results = {}
for i, v in enumerate(ini_pop):
A = np.vstack([v]*149)
results[i] = Existing_Value*A
ini_pop:
Out[62]:
array([[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
[0.88490691, 0.85060902, 0.02761904, 0.67543623, 0.24011947,
0.63160755],
[0.51655439, 0.8541867 , 0.30350761, 0.91582466, 0.92503826,
0.27640764],
[0.14740895, 0.48664955, 0.39666046, 0.03173014, 0.44483261,
0.81007225],
[0.41793196, 0.63657912, 0.66755118, 0.56862476, 0.6962219 ,
0.36292305],
[0.99399587, 0.41775574, 0.15244959, 0.66047238, 0.27718652,
0.29360273],
[0.72210127, 0.51900693, 0.53540488, 0.91054719, 0.23536984,
0.21565889],
[0.98030203, 0.47739105, 0.22477224, 0.63551278, 0.73896193,
0.06814704],
[0.0152948 , 0.08646868, 0.42559336, 0.44558531, 0.29017913,
0.64896315],
[0.06043923, 0.83571793, 0.21154994, 0.87061577, 0.23682892,
0.31632989]])
現有值:
Out[63]:
array([[1, 1, 0, 0, 0, 1],
[0, 1, 1, 1, 0, 1],
[1, 1, 0, 0, 1, 0],
[0, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 0, 1],
[1, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 1, 0],
[0, 1, 1, 0, 0, 0],
[1, 0, 1, 1, 0, 0],
[0, 0, 1, 0, 1, 1],
[1, 0, 1, 0, 0, 1],
[1, 1, 1, 0, 1, 1],
...
A(對於 ini_pop 的第一行):
Out[67]:
array([[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
[0.597996 , 0.48470908, 0.34200821, 0.48973549, 0.31928532,
0.00990472],
...
結果存儲為字典,由 ini_pop 的每一行乘以 Existing_value 的整體組成(因此字典中存儲了 10 個值,每個 ini_pop 行一個)。
這是結果[0]:
Out[69]:
array([[0.597996 , 0.48470908, 0. , 0. , 0. ,
0.00990472],
[0. , 0.48470908, 0.34200821, 0.48973549, 0. ,
0.00990472],
[0.597996 , 0.48470908, 0. , 0. , 0.31928532,
0. ],
[0. , 0.48470908, 0.34200821, 0. , 0.31928532,
0. ],
[0. , 0.48470908, 0.34200821, 0.48973549, 0. ,
0. ],
[0. , 0. , 0. , 0.48973549, 0. ,
0.00990472],
[0.597996 , 0.48470908, 0. , 0.48973549, 0. ,
0.00990472],
[0.597996 , 0. , 0. , 0. , 0.31928532,
0. ],
[0. , 0.48470908, 0.34200821, 0. , 0. ,
0. ],
[0.597996 , 0. , 0.34200821, 0.48973549, 0. ,
0. ],
[0. , 0. , 0.34200821, 0. , 0.31928532,
0.00990472],
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.