numerical

bash short by two columns

烂漫一生 提交于 2019-12-13 07:57:07
问题 I've this dataset: 12363 111111 12363 222222 12363 3456 12364 2895 12364 257363 12364 246291 12364 243701 12364 243699 I would like to sort this by first column, numerical value, reverse and by second column, numerical value, reverse. Result would be: 12364 257363 12364 246291 12364 243701 12364 243699 12364 2895 12363 222222 12363 111111 12363 3456 I tried, sort -rn sort -rnk1,2 sort -rg sort -rgk1,2 But somehow all of these gives back for the second column a wrong order (not numerical, but

Is this C callback safe with C++ objects?

这一生的挚爱 提交于 2019-12-13 00:32:53
问题 My purpose is to call some C function from my C++ code and pass some C++ objects. In fact I am using a integration routine from the GSL libray(written in C), see this link, My code snippet: // main.cpp #include <stdio.h> #include <gsl/gsl_integration.h> #include <myclass.h> /* my test function. */ double testfunction ( double x , void *param ) { myclass *bar=static_cast<myclass*>(param); /*** do something with x and bar***/ return val; } int main ( int argc , char *argv[] ) { gsl_function F;

Dynamic json object with numerical keys

旧巷老猫 提交于 2019-12-12 15:03:42
问题 I have a json object which I converted to dynamic C# object with help of this answer. It works just fine, but trouble is that this object has numerical keys. For instance, var jsStr = "{address:{"100": {...}}}"; So I can't wirte dynObj.address.100 And, as I know, I can't use indexers to get this object like this dynObj.address["100"] Please explain to me how I can get this working. 回答1: As far as I can see from the source code he resolves the properties through a private dictionary, so you

Global overloading of == and != for floating-points

一世执手 提交于 2019-12-12 14:21:58
问题 Is it a bad practice to overload global operator == and != for floating points ? I'm using fast floating-points in a game environement, and i was thinking about using fuzzy comparison everywhere as i can't imagine a situation where i don't expect extremely close numbers not to be equals. Any advice ? 回答1: Other posts mentioned technical problems, from another perspective: Its a bad practice because nobody expects these operators to be overloaded, while reasonable people will expect an

OpenCV:src is not a numerical tuple

爷,独闯天下 提交于 2019-12-12 09:36:33
问题 I've written a program about color detection by using python. But always there's an error around the 'Erode' sentence. Here's part of my program. Thank you. # Convert the image to a Numpy array since most cv2 functions # require Numpy arrays. frame = np.array(frame, dtype=np.uint8) threshold = 0.05 #blur the image frame=cv2.blur(frame, (5,5)) #Convert from BGR to HSV hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) #split into 3 h, s, v= cv2.split(hsv) #red color s = cv2.threshold(h, 15, 1, cv2

Is there a way to reduce scipy/numpy precision to reduce memory consumption?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:48:18
问题 On my 64-bit Debian/Lenny system (4GByte RAM + 4GByte swap partition) I can successfully do: v=array(10000*random([512,512,512]),dtype=np.int16) f=fftn(v) but with f being a np.complex128 the memory consumption is shocking, and I can't do much more with the result (e.g modulate the coefficients and then f=ifftn(f) ) without a MemoryError traceback. Rather than installing some more RAM and/or expanding my swap partitions, is there some way of controlling the scipy/numpy "default precision" and

multiplication of 3 matrices in a sum

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:24:33
问题 I want to compute: result = SUM (c=0,N) { V_ck * U_lc * S_c } But my 2D matrices are indexed as 1D and stored as column major. I am trying: float *A,*B; int M,N; A = (float *) malloc( M * N * sizeof(float) ); B = (float *) malloc( M * sizeof(float) ); float *S = (float *)malloc( N * sizeof( float) ); float *U = (float *)malloc( M * M * sizeof( float) ); float *V = (float *)malloc( N * N * sizeof( float) ); float * result = (float *) malloc( M * N * sizeof(float) ); float thesum=0; for (int k

Scipy integrate.quad not returning the expected values

≡放荡痞女 提交于 2019-12-12 04:16:07
问题 I have the following function which I would like to numerically integrate using python, Using scipy, I have written this code: def voigt(a,u): fi = 1 er = Cerfc(a)*np.exp(np.square(a)) c1 = np.exp(-np.square(u))*np.cos(2*a*u) c1 = c1*er #first constant term pis = np.sqrt(np.pi) c2 = 2./pis #second constant term integ = inter.quad(lambda x: np.exp(-(np.square(u)- np.square(x)))*np.sin(2*a*(u-x)), 0, u) print integ ing = c1+c2*integ[0] return ing For the Cerfc(a) function, I just use scipy.erfc

Behavior of Scala for/comprehension implicit transformation of numerical types?

孤者浪人 提交于 2019-12-12 00:53:03
问题 I'm trying to understand the behavior of Scala for-loop implicit box/unboxing of "numerical" types. Why does the two first fail but not the rest? 1) Fails: scala> for (i:Long <- 0 to 10000000L) {} <console>:19: error: type mismatch;<br> found : Long(10000000L) required: Int for (i:Long <- 0 to 10000000L) {} ^ 2> Fails: scala> for (i <- 0 to 10000000L) {} <console>:19: error: type mismatch; found : Long(10000000L) required: Int for (i <- 0 to 10000000L) {} ^ 3) Works: scala> for (i:Long <- 0L

Sorting Numerical Data Alphabetically

家住魔仙堡 提交于 2019-12-11 15:54:35
问题 Are there any situations where it's useful to sort numerical data alphabetically? for e.g. 111 12 2 when sorted in ascending order,give: 111 12 2 回答1: I can't think of any good reasons, and it's just going to confuse in general. 回答2: I finally thought of one. When investigating Benford's Law. Also, when the data isn't really "numerical", it's strings which just happen to consist only of digits, but which need to be lexically sorted along with other strings that might contain non-digits. But I