floor

math_ops.floor equivalent in Keras

筅森魡賤 提交于 2019-12-20 01:46:52
问题 I'm trying to implement a custom layer in Keras where I need to convert a tensor of floats [a, 1+a) to a binary tensor for masking. I can see that Tensorflow has a floor function that can do that, but Keras doesn't seem to have it in keras.backend . Any idea how I can do this? 回答1: As requested by OP, I will mention the answer I gave in my comment and elaborate more: Short answer: you won't encounter any major problems if you use tf.floor() . Long answer: Using Keras backend functions (i.e.

Floor or ceiling of a pandas series in python?

柔情痞子 提交于 2019-12-18 11:40:36
问题 I have a pandas series series . If I want to get the element-wise floor or ceiling, is there a built in method or do I have to write the function and use apply? I ask because the data is big so I appreciate efficiency. Also this question has not been asked with respect to the Pandas package. 回答1: You can use NumPy's built in methods to do this: np.ceil(series) or np.floor(series) . Both return a Series object (not an array) so the index information is preserved. 回答2: You could do something

Why do lots of (old) programs use floor(0.5 + input) instead of round(input)?

旧城冷巷雨未停 提交于 2019-12-18 11:14:46
问题 The differences reside in the returned value giving inputs around tie-breaking I believe, such as this code: int main() { std::cout.precision(100); double input = std::nextafter(0.05, 0.0) / 0.1; double x1 = floor(0.5 + input); double x2 = round(input); std::cout << x1 << std::endl; std::cout << x2 << std::endl; } which outputs: 1 0 But they are just different results in the end, one chooses its preferred one. I see lots of "old" C/C++ programs using floor(0.5 + input) instead of round(input)

Does casting to an int after std::floor guarantee the right result?

六眼飞鱼酱① 提交于 2019-12-17 07:23:37
问题 I'd like a floor function with the syntax int floor(double x); but std::floor returns a double . Is static_cast <int> (std::floor(x)); guaranteed to give me the correct integer, or could I have an off-by-one problem? It seems to work, but I'd like to know for sure. For bonus points, why the heck does std::floor return a double in the first place? 回答1: The range of double is way greater than the range of 32 or 64 bit integers, which is why std::floor returns a double . Casting to int should be

Rounding to nearest fraction (half, quarter, etc.)

£可爱£侵袭症+ 提交于 2019-12-17 05:49:09
问题 So, I need to create the following functions but my head can't think of any possibility in PHP without complicated math. Round always up to the nearest decimal (1.81 = 1.90, 1.89 = 1.90, 1.85 = 1.90) Round always down to the nearest decimal (1.81 = 1.80, 1.89 = 1.80, 1.85 = 1.80) Round always up to the nearest x.25 / x.50 / x.75 / x.00 (1.81 = 2, 1.32 = 1.50) Round always down to the nearest x.25 / x.50 / x.75 / x.00 (1.81 = 1.75, 1.32 = 1.25) Round always up to the nearest x.50 / 1 (1.23 = 1

Round minute down to nearest quarter hour

我的梦境 提交于 2019-12-17 02:29:14
问题 I need to round times down to the nearest quarter hour in PHP. The times are being pulled from a MySQL database from a datetime column and formatted like 2010-03-18 10:50:00 . Example: 10:50 needs to be 10:45 1:12 needs to be 1:00 3:28 needs to be 3:15 etc. I'm assuming floor() is involved but not sure how to go about it. Thanks 回答1: Your full function would be something like this... function roundToQuarterHour($timestring) { $minutes = date('i', strtotime($timestring)); return $minutes - (

TSQL number rounding issue

不想你离开。 提交于 2019-12-13 08:10:23
问题 I have a piece of code: IF OBJECT_ID(N'dbo.rounding_testing') IS NOT NULL DROP FUNCTION dbo.rounding_testing; GO CREATE FUNCTION dbo.rounding_testing ( @value FLOAT, @digit INT ) RETURNS FLOAT BEGIN DECLARE @factor FLOAT, @result FLOAT; SELECT @factor = POWER(10, @digit); SELECT @result = FLOOR(@value * @factor + 0.4); RETURN @result; END; GO SELECT dbo.rounding_testing(5.7456, 3); SELECT FLOOR(5.7456 * 1000 + 0.4); The results are: 5745 5746 I'm expecting two 5746. I tried to debug the

Using round function in R on very small values returns zero

偶尔善良 提交于 2019-12-12 18:22:21
问题 I sometimes have to deal with very low p values and present them in a tabular format. The values returned by R can have long significance digits (i.e. digits after the decimal point). Now since the p value is anyways so low , I tend to shorten them before writing them into a .xls or .tsv files.(Just to make the tables look pretty !!) I am using R version 3.0.0 (2013-04-03) Some background and examples : 9.881313e-208 in R will be 9.88e-208 in my table I can use the round function in R to do

Java: BigInteger floor and ceil functions [closed]

回眸只為那壹抹淺笑 提交于 2019-12-11 11:28:59
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to implement an RSA attack in Java and I need to compute math operations like floor and ceil to BigInteger variables. As we know math.ceil and math.floor only apply to double variables, do you know any

CEIL and FLOOR in SQLite

人盡茶涼 提交于 2019-12-10 21:09:16
问题 What is the cleanest method to find the ciel and floor of a number in SQLite ? Unfortunately SQLite only has ROUND() function. 回答1: Formulas Ceil : cast ( x as int ) + ( x > cast ( x as int )) Take integer part of x and add 1 if decimal value is greater than 0 Floor : cast ( x as int ) - ( x < cast ( x as int )) Take integer part of x and subtract 1 if decimal value is less than 0 Examples Ceil : SELECT (cast ( amount as int ) + ( amount > cast ( amount as int ))) AS amount FROM SALES WHERE