简体   繁体   English

如果我有两个矩阵并且我想划分数据并希望在 Python 中保持相同的一致性(Nones 保持不变)?

[英]If I have two matrices and I want to divide the data and want to keep the same consistency (the Nones stay where they are) in Python?

Data is below:数据如下:

I want to get:我想得到:

Salaries / Games

However, get: TypeError Traceback (most recent call last) in ----> 1 SalaryGames = Salary / Games但是,在----> 1 SalaryGames = Salary / Games 中得到:TypeError Traceback (last last call last)

TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType' TypeError:不支持的操作数类型/:“NoneType”和“NoneType”

#Salaries
KobeBryant_Salary = [15946875,17718750,19490625,21262500,23034375,24806250,25244493,27849149,None,None]
JoeJohnson_Salary = [12000000,12744189,13488377,14232567,14976754,16324500,18038573,19752645,21466718,23180790]
LeBronJames_Salary = [4621800,5828090,13041250,14410581,15779912,14500000,16022500,17545000,19067500,20644400]
CarmeloAnthony_Salary = [3713640,4694041,13041250,14410581,15779912,17149243,18518574,19450000,22407474,22458000]
DwightHoward_Salary = [4493160,4806720,6061274,13758000,15202590,16647180,18091770,19536360,20513178,21436271]
ChrisBosh_Salary = [3348000,4235220,12455000,14410581,15779912,14500000,16022500,17545000,19067500,20644400]
ChrisPaul_Salary = [3144240,3380160,3615960,4574189,13520500,14940153,16359805,17779458,18668431,20068563]
KevinDurant_Salary = [0,0,4171200,4484040,4796880,6053663,15506632,16669630,17832627,18995624]
DerrickRose_Salary = [0,0,0,4822800,5184480,5546160,None,None,None,None]
DwayneWade_Salary = [3031920,3841443,13041250,14410581,15779912,14200000,15691000,17182000,18673000,15000000]
#Matrix
Salary = np.array([KobeBryant_Salary, JoeJohnson_Salary, LeBronJames_Salary, CarmeloAnthony_Salary, DwightHoward_Salary, ChrisBosh_Salary, ChrisPaul_Salary, KevinDurant_Salary, DerrickRose_Salary, DwayneWade_Salary])

#Games 
KobeBryant_G = [80,77,82,82,73,82,58,78,None,None]
JoeJohnson_G = [82,57,82,79,76,72,60,72,79,80]
LeBronJames_G = [79,78,75,81,76,79,62,76,77,69]
CarmeloAnthony_G = [80,65,77,66,69,77,55,67,77,40]
DwightHoward_G = [82,82,82,79,82,78,54,76,71,41]
ChrisBosh_G = [70,69,67,77,70,77,57,74,79,44]
ChrisPaul_G = [78,64,80,78,45,80,60,70,62,82]
KevinDurant_G = [35,35,80,74,82,78,66,81,81,27]
DerrickRose_G = [40,40,40,81,78,81,None,None,None,None]
DwayneWade_G = [75,51,51,79,77,76,49,69,54,62]
#Matrix
Games = np.array([KobeBryant_G, JoeJohnson_G, LeBronJames_G, CarmeloAnthony_G, DwightHoward_G, ChrisBosh_G, ChrisPaul_G, KevinDurant_G, DerrickRose_G, DwayneWade_G])

Change all None to np.nan .将所有None更改为np.nan That should do the trick.这应该够了吧。

https://colab.research.google.com/drive/1JXdLQvZwkU7Y2wrSM7sLbVlFxBdSHVEq?usp=sharing&fbclid=IwAR1SUEl4_h7Wa8exAlkCUNbOVnDBj3_z73PoqGhIgmsixKDSyPcVyOW04O8 https://colab.research.google.com/drive/1JXdLQvZwkU7Y2wrSM7sLbVlFxBdSHVEq?usp=sharing&fbclid=IwAR1SUEl4_h7Wa8exAlkCUNbOVnDBj3_z73PoqGhIgmsixKDSycP

See the graphs at the end.见最后的图表。 There's too many injuries and when a number goes from 1000 to 0 it makes the lines get skewed.受伤太多了,当一个数字从 1000 变为 0 时,它会使线条歪斜。 Thanks to all the answers!感谢所有的答案!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有两个矩阵已转换为灰度图像,我想找到它们之间的平均 SSIM 值(python) - I have two matrices that I have converted to a grayscale image and I want to find the mean SSIM value between them (python) Python:如果出现错误,我想留在脚本中 - Python: if error raised I want to stay in script 添加 function 不起作用 - 我想要的是能够对两个矩阵求和 - Add function not working - what I want is to be able to sum two matrices 如何对角分割两个矩阵 - How do I diagonally divide two matrices 对于 Python,我想添加字符串的最后两个值,但我想将两位数字放在一起,并且不在字符串索引中包含空格 - With Python, I want to add the last two values of a string but I want to keep double digit numbers together and not include spaces in the string index 我想同时运行两个函数 - I want to run two functions at same time 我有两个数据框 df 和 df1 具有相同的 id 列,但两个数据框中的列名不同,我想在第二个 dataframe 中更新值 - I have a two data frames df and df1 have same id columns but different column names in both data frames and I want update values in second dataframe 我想自动化一个必须使用python运行truncate命令的过程 - I want to automate a process where I have to run truncate command with python 我想匹配python中的两个dataframe列 - i want to match two dataframe columns in python 我有一个列表,其中是字符串,我想删除 [ ] - I have a list where is are strings, I want to remove the [ ]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM