math

math.cos(x) not returning correct value?

两盒软妹~` 提交于 2020-07-03 16:57:43
问题 I just started using python, and am having difficulty with a very basic program. I want to calculate the cosine of -20 degrees. It is my understanding that the default value is in radians, so this is the following code i tried: import math print math.cos(math.degrees(-20)) This outputs (-.7208...), where the answer is actually (.9397...). I'm sure this has a pretty basic solution but I've tried so many different things and it will not output the correct results. Thanks in advance! 回答1: Per

How to detect when rotated rectangles are colliding each other

只愿长相守 提交于 2020-07-03 13:00:47
问题 After saw this question many times and replied with an old (an not usable) code I decide to redo everything and post about it. Rectangles are defined by: center : x and y for his position (remember that 0;0 is TOP Left, so Y go down) size : x and y for his size angle for his rotation (in deg, 0 deg is following axis OX and turn clockwise) The goal is to know if 2 rectangles are colliding or not. 回答1: Will use Javascript in order to demo this (and also provide code) but I can be done on every

Is there has a function Math.Pow(A,n) for long type?

半城伤御伤魂 提交于 2020-07-03 10:19:13
问题 I'm testing a small C# program fragment: short min_short = (short)(int)-Math.Pow(2,15); short max_short = (short)(int)(Math.Pow(2, 15) - 1); Console.WriteLine("The min of short is:{0};\tThe max of short is:{1}", min_short, max_short); int min_int = (int)-Math.Pow(2, 31); int max_int = (int)(Math.Pow(2, 31) - 1); Console.WriteLine("The min of int is:{0};\tThe max of int is:{1}", min_int, max_int); uint min_uint = 0; uint max_uint = (uint)(Math.Pow(2, 32) - 1); Console.WriteLine("The min of

Is it possible to predict future 2FA values given older values with timestamps?

ⅰ亾dé卋堺 提交于 2020-07-03 10:01:12
问题 Is it safe to share 2FA codes? I'm talking about TOTP like Google Authenticator or Authy . For example, if i have code and generation time, is it possible to predict new codes? What if i have more than 1 pair of code+time? I think it's possible to predict new codes based on old information (code+time). So if this is possible, how do I do it? Im looking for some algorithm. Known Time period, time, code and secret length. Example: 22:20:30 561918 22:21:00 161664 22:21:30 610130 回答1: Internally,

Make a number a percentage

£可爱£侵袭症+ 提交于 2020-07-02 04:32:29
问题 What's the best way to strip the "0."XXX% off a number and make it a percentage? What happens if the number happens to be an int? var number1 = 4.954848; var number2 = 5.9797; $(document).ready(function() { final = number1/number2; alert(final.toFixed(2) + "%"); }); 回答1: A percentage is just: (number_one / number_two) * 100 No need for anything fancy: var number1 = 4.954848; var number2 = 5.9797; alert(Math.floor((number1 / number2) * 100)); //w00t! 回答2: ((portion/total) * 100).toFixed(2) + '

Random number generation following a Poisson distribution

好久不见. 提交于 2020-06-29 05:13:08
问题 I have prepared a code in Python to do random sampling of beam structure and looking for photons. The evolution of photons with time follows a Poisson distribution. The beam structure I am simulating has 936 bins with first 900 bins having charge of 0.62 nC followed by a gap of 36 bins. Each bin is of 2 ns which means total revolution period of the beam (to complete one circle of synchrotron) is 1.872 microseconds (936 bins time 2 ns). We look for probability of getting photons in each bin.

How to Calculate Average Scroll Depth?

半城伤御伤魂 提交于 2020-06-29 04:24:09
问题 I am trying to calculate the average scroll depth of a page on a website. In Google Analytics, I have events that fire at milestones of 10% increments—so when a user reaches 10% down the page, 20%, 30%, and so on. I have have a custom metrics for each milestone (so I can track via the metrics or via the events). My question is: with this information, how to I calculate the average scroll depth of the page ? Or in other words, how do I find the average distance a user will scroll down the page

How to Calculate Average Scroll Depth?

早过忘川 提交于 2020-06-29 04:22:20
问题 I am trying to calculate the average scroll depth of a page on a website. In Google Analytics, I have events that fire at milestones of 10% increments—so when a user reaches 10% down the page, 20%, 30%, and so on. I have have a custom metrics for each milestone (so I can track via the metrics or via the events). My question is: with this information, how to I calculate the average scroll depth of the page ? Or in other words, how do I find the average distance a user will scroll down the page

Is it possible to update the learning rate, each batch, based on batch label (y_true) distribution?

拈花ヽ惹草 提交于 2020-06-28 09:54:07
问题 Edit: See end of this question for the Solution TL;DR: I need to find a way to calculate the label distribution per-batch, and update the learning rate . Is there a way to access the optimizer of the current model to update the learning_rate, per batch? Below is how to calculate the label distribution. It can be done in the loss function, as by default the loss is calculated batch-wise. Where can this code be executed which also has access to the model's optimizer? def loss(y_true, y_pred): y

SymPy: Factorization of polynomials over symbolic roots with combined square roots

╄→гoц情女王★ 提交于 2020-06-28 03:55:32
问题 SymPy factor function can factorize over symbolic roots, e.g. : In [1]: from sympy import * In [2]: init_printing(use_latex=False) In [3]: z, a, b = symbols('z a b') In [4]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [5]: poly Out[5]: 2 √a⋅√b - √a⋅z - √b⋅z + z In [6]: factor(poly, z) Out[6]: (-√a + z)⋅(-√b + z) but the factorization fails if b = a : In [10]: b = a In [11]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [12]: poly Out[12]: 2 -2⋅√a⋅z + a + z In [13]: factor(poly, z) Out