numeric

R right matrix division

杀马特。学长 韩版系。学妹 提交于 2019-12-10 15:29:50
问题 What's the most succinct, fastest, most numerically stable, most R-idiomatic way to do left and right matrix division in R? I understand left division inv(A)*B is usually done with solve(a,b) , but how about B*inv(A) ? Is the best way really to compute t(solve(t(A),t(B))) ? 回答1: I don't have a solution better than B %*% solve(A) , but I did want to point out that in general solve(A,B) is faster and more numerically stable than solve(A) %*% B . > A = matrix(rnorm(10000),100,100) > B = matrix

Python: Strip Everything but Numbers

对着背影说爱祢 提交于 2019-12-10 15:16:11
问题 I have to extract a number (a measured time value) from each of several strings. How could I do this elegantly? All numbers are positive and have a maximum of two decimal places. (E.g.: 2.3/ 40.09/ 101.4 - no numbers in E notation). The code I am looking for should do something like the following pseudocode: >>> "It took 2.3 seconds".strip(everything but ".1234567890") 2.3 回答1: Instead of strip, select for the numbers with a regular expression: import re numbers = re.compile('\d+(?:\.\d+)?')

how to visualize values on logarithmic scale on matplotalib?

南楼画角 提交于 2019-12-10 13:23:14
问题 I have vales with very small difference like... 0.000001. I want to visualize them on logarithmic scale. I am wondering how to do it in matplotlib. Thanks a lot 回答1: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis Simply add the keyword argument log=True Or, in an example: from matplotlib import pyplot import math pyplot.plot([x for x in range(100)],[math.exp(y) for y in range(100)] ) pyplot.xlabel('arbitrary') pyplot.ylabel('arbitrary') pyplot.title('arbitrary')

Compute the multivariate normal CDF in Java

懵懂的女人 提交于 2019-12-10 13:07:46
问题 Does anyone know of a reliable, accurate library to compute the multivariate normal (MVN) CDF in Java? I'm looking for something like MATLAB's mvncdf function. I need to be able to do it for dimensions of up to 10 or more. Most statistics/math libraries don't have this functionality. Being able to compute the log probability is a plus. From this post, there doesn't seem to be a free implementation mentioned for some other languages. While a straight-java implementation would rock, I would

Create a numeric text box in java Swing with increment and decrement buttons

前提是你 提交于 2019-12-10 12:38:43
问题 How can I create a numeric text box in java swing , which has two buttons (up and down) which increments and decrements the value in the text box respectively. Also this text box must be editable with ONLY NUMERIC VALUES . Something like this I tried by placing two buttons near a text box and manually doing the operation on button click. Is there any other method in which I can do this in a better way and achieve a similar result as the first image. Thanks :) 回答1: Use JSpinner How to use

PHP - Sort Two Arrays The Same Way

情到浓时终转凉″ 提交于 2019-12-10 10:47:10
问题 I have two different arrays. One array, a, for a list of people. My other array, b, for a list of their ages. I go to sort b by number and then reverse it so it goes in descending order. I got to this part okay. How do I sort a (a list of people's names) so that the same values are still paired up with the sorted list? Example: a contains Bob, Sue, Phil, and Jenny respectively b contains 15, 12, 13, and 13 respectively. I want my outcome to be: a contains Bob, Jenny, Phil, and Sue

PHP float bug: PHP Hangs On Numeric Value

佐手、 提交于 2019-12-10 09:28:17
问题 I just read an interesting article about php hanging on certain float numbers, see The Register and Exploring Binary. I never explicitly use floats, I use number_format() to clean my input and display for example prices. Also, as far as I am aware, all input from for example forms are strings until I tell them otherwise so I am supposing that this problem does not affect me. Am I right, or do I need to check for example Wordpress and Squirrelmail installations on my server to see if they cast

Converting from unsigned long long to float with round to nearest even

痴心易碎 提交于 2019-12-10 09:25:57
问题 I need to write a function that rounds from unsigned long long to float, and the rounding should be toward nearest even. I cannot just do a C++ type-cast, since AFAIK the standard does not specify the rounding. I was thinking of using boost::numeric, but i could not find any useful lead after reading the documentation. Can this be done using that library? Of course, if there is an alternative, i would be glad to use it. Any help would be much appreciated. EDIT: Adding an example to make

python numpy.convolve to solve convolution integral with limits from 0 to t instead -t to t

烂漫一生 提交于 2019-12-10 05:35:44
问题 I have a convolution integral of the type: To solve this integral numerically, I would like to use numpy.convolve() . Now, as you can see in the online help, the convolution is formally done from -infinity to +infinity meaning that the arrays are moved along each other completely for evaluation - which is not what I need. I obviously need to be sure to pick the correct part of the convolution - can you confirm that this is the right way to do it or alternatively tell me how to do it right and

Tracing Python warnings/errors to a line number in numpy and scipy

笑着哭i 提交于 2019-12-10 01:47:54
问题 I am getting the error: Warning: invalid value encountered in log From Python and I believe the error is thrown by numpy (using version 1.5.0). However, since I am calling the "log" function in several places, I'm not sure where the error is coming from. Is there a way to get numpy to print the line number that generated this error? I assume the warning is caused by taking the log of a number that is small enough to be rounded to 0 or smaller (negative). Is that right? What is the usual