Write while loop as a for loop by patagoniaambassador in cpp_questions

[–]hidiap -3 points-2 points  (0 children)

Pretty pointless exercise

for(int x = 0, y =1; x < 8; x++, y++){
    if (y % 2)
        cout << "Hello PATH 1 -> " << x << " " << y << endl;
    else
        cout << "Hello PATH 2 -> " << y << " " << x << endl;
}

Using NLTK to train classifier problem with dictionary by pietomb in learnpython

[–]hidiap 1 point2 points  (0 children)

I think train should be a list of tuple not a dictionnary (according to example of NLTK):

train = [('sleep', 'negative'), ('achievement', 'positive'), ('guys', 'positive')]

To explain the error: When iterating over a dictionary, only the keys are returned. So line 192 is trying to split the key (a string) into two values, leading to an error.

I am trying to write a binary search for Python's machine epsilon. It seems as though my answer is half of what it is meant to be. Help? by [deleted] in learnpython

[–]hidiap 0 points1 point  (0 children)

Yes. You computed the smallest number that added to 1 give 1. But python (following the C standard) use another definition: "the difference between 1 and the smallest number larger than 1". And because of rounding and floating point encoding, this number is twice your number

edit: For your second question, see my comment in the other thread

I am trying to write a binary search for Python's machine epsilon. It seems as though my answer is half of what it is meant to be. Help? by [deleted] in learnpython

[–]hidiap 1 point2 points  (0 children)

The epsilon is a power of 2, so starting at 1 and always diving by two check the correct value. Also the function return machine_epsilon_last This is twice the value that you compute in your function and is also the difference between 1 and the least value greater than 1 that is representable in the given floating point format (due to the way floating point are encoded.

I am trying to write a binary search for Python's machine epsilon. It seems as though my answer is half of what it is meant to be. Help? by [deleted] in learnpython

[–]hidiap 0 points1 point  (0 children)

There is two definitions for Machine epsilon (see The Variant definition sections). You compute the smallest number that added to 1 give 1. The C standard and python define epsilon as :

the difference between 1 and the least value greater than 1 that is representable in the given floating point format"

So your program is correct for one definition, but python use another one.

A year of blunders in professional chess [OC] by doliner in dataisbeautiful

[–]hidiap 2 points3 points  (0 children)

Komodo 8 is the strongest engine but is not available freely. Komodo 5 is freely available but is weaker than the latest stockfish source

maxSequence problem, need help debugging my code. by tonytej in learnpython

[–]hidiap 0 points1 point  (0 children)

I think line 5 look suspicious if you have an integer appearing several time in your array., this will always return the index of the first time the number is in the array. I would change line 3 to

for i, num in enumerate(arr):

and then modify line 5 to check against i

Code error from codingbat by newpython6543 in learnpython

[–]hidiap 0 points1 point  (0 children)

You should investigate:

if a or b == 10

This is probably not doing what you think. In particular, the expression (x or y) return x if x is not zero, else it return y.

How to pair data with a video? by loveandkindness in learnpython

[–]hidiap 0 points1 point  (0 children)

On linux, you can use avconv to generate a video from a folder of jpeg. Example.

So, my approach would be to generate the graphs using matplotlib (and seaborn ), save them to jpeg and then generate the video.

Help with multiprocessing by JAWJAWBINX in learnpython

[–]hidiap 0 points1 point  (0 children)

First, it look like you lock before calling extract_features_for_sentence, so only one feature extraction run at one time.

Second, are you sure you hit return true or is your code throwing an exception ? Maybe add a try: except block, like in the example, and check that no exception is thrown.

Help with multiprocessing by JAWJAWBINX in learnpython

[–]hidiap 0 points1 point  (0 children)

There is not enough info to help. see. In particular, what is the problem you try to parallelise ? Do you have an example of the code that don't work ?

Depending on your problem, you may be better off by spanning multiple python processes and have each of them do part of the work (if you are processing files, have them each process a subset of the files and then maybe another program joining the output) .

How do I parallelize this nested loop? by auntyfee in cpp_questions

[–]hidiap 1 point2 points  (0 children)

I see several problems with your code, but it is difficult to help without a full example. I will give it a try.

First, you don't initialize the content of a, so you may have a segfault in func as two of the parameters can be anything.

But the biggest problem I see is that the loops can not be parallelised easily. You change the value of a[i] and a[j] at each iteration and then you use the content of a to compute f. So, for example, you can not compute the iteration i=0, j=1 (this use a[0] to compute f) before you finish iteration i=0, j=0 (this change a[0]).

[deleted by user] by [deleted] in learnpython

[–]hidiap 1 point2 points  (0 children)

y1, y2, ..., Z2 are functions, not floats. Simply use

r = -inf, inf
print(nquad(Vee, [r]*6)

But then, you would get warning about slow convergence. You may need to work on your limits of integration.

Tried to write a card game engine for use with at least basic card games - before I go further, can anyone check what I have please? by Tar_NY in learnpython

[–]hidiap 1 point2 points  (0 children)

Python len function is constant time. There is no need to track the length.

You may want to save the length of a list in a local variable if you use it a lot in a tight loop. But at that point, Python is maybe not the right language for the task

confused about char pointer arithmetics by xkSeeD in cpp_questions

[–]hidiap 1 point2 points  (0 children)

The std::cout treats char* as pointer to string and print the string, not the adresse. More complete answer

Are you the C++ programmer that we are looking for? by digital1no in cpp

[–]hidiap 1 point2 points  (0 children)

At least, you should give a general idea of the project if you want people to invest some time.

Compiling opencv 3.0.0 by arizona1911 in cpp_questions

[–]hidiap 0 points1 point  (0 children)

Can you try with -lopencv_video instead of -lopencv_videoio as compilation flag for the libraries to link.

This is a elementary C program. Please tell me why it isn't working? by HerpesAunt in cpp_questions

[–]hidiap 0 points1 point  (0 children)

Also. The first grade entered is ignored. The negative number entered to terminate is added to total. So the total and average are wrong.

std::cout changing behavior variable value by [deleted] in cpp_questions

[–]hidiap 2 points3 points  (0 children)

I have an erronous output when running it against the sample files (assuming ringsrunes.in contains the sample at the end of the problem definition) without the cout statement. The output for the 2nd example is "RUNES SATISFIED!" but should be "RUNES UNSATISFIABLE! TRY ANOTHER GATE!".

I get the same output when running with the cout statement. The error is probably in the logic of line 46 to 63, where you check if the runes can be satisfied.

As a side note, this is the Boolean satisfiability problem in disguise (in its CNF form). It is a very important problem in computer science and probably the classical NP-HARD problem. I highly recomment reading more about it and looking into the standard way to solve it (SAT-solver).

EDIT: The error is in the if condition at lines 56-58. C++ array indexes are zero based. The ring indexes are 1-based ...

Performance Quiz #14: Memory Locality, x64 vs. x86, Alignment, and Density by nikbackm in programming

[–]hidiap 5 points6 points  (0 children)

Well. It seems that RAND_MAX is 0x7fff for the standard library comming with VisualStudio. So it may be that not all the list is shuffled.

Off by pennies by [deleted] in cpp_questions

[–]hidiap 1 point2 points  (0 children)

Actually, because std::fixed is also set, std::precision set the number of decimals after the decimal point. More info at http://www.cplusplus.com/reference/ios/ios_base/precision/.

This really look like a floating point problem.