草庐IT

integer-math

全部标签

java - 为什么没有 Math.floor(float)?

为什么只有Math.floor(double)?我有一个float,我想将它“向下”舍入。我必须把它加倍吗? 最佳答案 它将自动转换(参见wideningprimitiveconversions)。但是,如果您希望将结果作为float,则需要显式转换返回值。 关于java-为什么没有Math.floor(float)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6060940

java - 为什么 foo(1,2,3) 没有作为 Integer[] 传递给可变参数方法 foo(Object...)

请注意以下代码行:publicstaticvoidmain(String[]args){foo(1,2,3);System.out.println("-------------------------------------");foo(newInteger(1),newInteger(2),newInteger(3));System.out.println("-------------------------------------");foo(newInteger[]{1,2,3});System.out.println("-----------------------------

python - 使用 math.atan2 计算线段之间的角度(Python)

我正在处理空间分析问题,此工作流的一部分是计算连接线段之间的角度。每条线段只由两个点组成,每个点都有一对XY坐标(笛卡尔坐标)。这是来自GeoGebra的图片。我一直对获得0到180度范围内的正角度很感兴趣。但是,根据输入线段中顶点的顺序,我会得到各种角度。我使用的输入数据以坐标元组的形式提供。根据顶点创建顺序,每条线段的最后一个/终点可能不同。以下是Python代码中的一些案例。我得到它们的线段顺序是随机的,但在元组的元组中,第一个元素是起点,第二个元素是终点。DE线段,例如,将有((1,1.5),(2,2))和(1,1.5)是起点,因为它在坐标元组中具有第一个位置。但是,我需要确保

Python:math.factorial 是否已内存?

我正在解决problem以三种不同的方式,其中两种是递归的,我自己记住了它们。另一个不是递归的,而是使用math.factorial。我需要知道是否需要向其添加显式内存。谢谢。 最佳答案 在此链接上搜索math_factorial,您将找到它在python中的实现:http://svn.python.org/view/python/trunk/Modules/mathmodule.c?view=markup附言这是针对python2.6的 关于Python:math.factorial是

python - 溢出错误 : math range error

>>>importmath>>>math.pow(2,3000)Traceback(mostrecentcalllast):File"",line1,inOverflowError:mathrangeerror我该如何解决? 最佳答案 使用内置运算符。2**3000 关于python-溢出错误:mathrangeerror,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/29886

python - 可能的 math.ceil() 错误

在Windows7Python3.2上,以下内容:print(int(math.ceil(24/10)))按预期给了我“3”。在带有ActivePython2.5的WindowsServer上,它给了我“2”。这是什么问题,我该如何解决?这是我的原始代码:number_of_pages=int(math.ceil(number_of_rows/number_of_rows_per_page))谢谢,巴里 最佳答案 Python2.x使用截断除法,所以24/10的答案是2。2的ceil仍然是2。修复方法是将其中一个操作数转换为floa

python - "an integer is required"以 utf-8 格式打开()文件时?

我有一个文件,我想用以下行在python中打开:f=open("C:/data/lastfm-dataset-360k/test_data.tsv","r","utf-8")调用这个给我错误TypeError:anintegerisrequired我删除了除该行之外的所有其他代码,但仍然出现错误。我做错了什么以及如何正确打开它? 最佳答案 来自open()的文档:open(name[,mode[,buffering]])[...]Theoptionalbufferingargumentspecifiesthefile’sdesire

python - 类型错误 : only integer scalar arrays can be converted to a scalar index with 1D numpy indices array

我想编写一个函数,根据提供的bin概率从训练集中随机挑选元素。我将集合索引分成11个bin,然后为它们创建自定义概率。bin_probs=[0.5,0.3,0.15,0.04,0.0025,0.0025,0.001,0.001,0.001,0.001,0.001]X_train=list(range(2000000))train_probs=bin_probs*int(len(X_train)/len(bin_probs))#extendprobabilitiesacrossbinelementstrain_probs.extend([0.001]*(len(X_train)-len(

python - TypeError : list indices must be integers, not str,while parsing json

提交请求后,我收到了以下json:{"type":[{"ID":"all","count":1,"references":[{"id":"Boston,MA,02118","text":"Boston,MA,02118","val":"Boston,MA,02118","type":1,"zip":"02118","city":"Boston","state":"MA","lt":"42.3369","lg":"-71.0637","s":""}]}]}我在变量j中捕获了响应并按如下方式加载它,l=json.loads(j)现在我有:>>>type(l)>>>l['type']['re

python - dtype : integer, 但 loc 返回 float

我有一个奇怪的数据集:yearfirmsagesurvival019775649180NaN219785039910NaN3197841313010.731310519794978050NaN6197939035210.774522我将前三列的dtype转换为整数:>>>df.dtypesyearint64firmsint64ageint64survivalfloat64但现在我想根据这里的索引在另一个表中搜索:idx=331otherDf.loc[df.loc[idx,'age']]Traceback(mostrecentcalllast):(...)KeyError:8.0这来自d