The Stack Overflow podcast is back! Listen to an interview with our new CEO.
24

A look at the second plot in the post shows that something has gone wrong. There are four points in a line here: This shouldn't be possible, since "points that create a straight line when plotted" have been removed. How did this happen? A look at the \$x\$ axis shows the cause. The first plot has the \$x\$ coordinate running from 0 to 96, but the second ...


12

Let's start with the obvious: this code doesn't run. You're missing ans = starter() so that further (el)if ans.lower() == ... doesn't miserably fail with a NameError. Likely, you define q() but never use it. And you also appears to have other useless stuff floating around: why use both textblob and indicoio to perform sentiment analysis? You also seem to ...


10

I have to admit that I have no idea what the purpose of the code is (never worked with speech recognition) but I know a little bit Python so I can give some advise on the code itself. Performance You expressed the desire to optimize the performance of your script. But do you know the first rule about optimization? If not, it is: Don't! The second rule is:...


10

You can use Ramer Douglas Peuker algorithm. RDP takes a curve and eliminates points that are close to straight lines. It is distance based. Starting with the two endpoints, it forms a line and picks the point furthermost away from it. That point is used to form line segments and iterate until all the remaining points are close to the line. Python has an RDP ...


10

The roll function generates a random sequence of integers. The loop body shows me that you know how to seed a pseudo-RNG with a true source of randomness but you're doing it for every iteration. You should seed the pseudo-RNG once and then use it in the loop. You know how big your rand vector will be by the time you're done with it so you should reserve ...


7

public class DateFormatter { static String date1 = ""; static String date2 = ""; static String date3 = ""; static String date4 = ""; static String date5 = ""; static String date6 = ""; static String date7 = ""; public static void dateFormatter(NumberAxis xAxis){ loadDates(); xAxis.setLowerBound(0.0); ...


7

I'm really sorry, but after starting this review I have to tell you: Go back, read some more tutorials and try again This code has so many issues, that I'm not able to point them out reasonably without saying something stupid and / or offensive, so I'll give you a few tips that should help you, if you rewrite this from scratch: Avoid static Like The ...


7

PyAudio doesn't seem to have a with interface, however you should add that interface to your class. PEP 343 explains why it was added to Python, but it mostly comes down to being syntactic sugar to a try finally. To add this is rather simple, you add __enter__ and __exit__ and that's it. The benefit to this, is you don't have to manually close the stream, as ...


7

Keeping all else untouched, this gives a 1000x performance boost: int w=1920,h=1080; uint64_t *buckets = (uint64_t*)calloc(w*h,sizeof(buckets)); double min_x,max_x,min_y,max_y; min_x = max_x = roots[0]; min_y = max_y = roots[1]; for ( int i = 0; i < cur_root; i+=2 ) { min_x = roots[i]<min_x?roots[i]:min_x; ...


7

First of all, congratulations, the result looks really good and that's a lot of work for an exercise! I particularly like how you frequently used standard algorithms. That is also quite a lot of code to review! You'll excuse me if I don't review it all, actually a tiny part of it. But rather than getting into the details, I'll underline an important ...


6

Summary Fix the bugs. Make sure your source code can be understood. Further improve your symbol names. Write more, shorter methods. Use Formatter. Use smarter algorithms. Use Stream.collect() to create the second histogram. Unit test. Fix the bugs When you have a user which consumes less than 10 bytes of data, you don't count that. I think that's a bug. I ...


6

Setting aside PEP 8 (official style guide) issues I would make the following change: Rather than keeping your politician bins, names and email addresses in separate data structures (the only way they are tied right now is by the array index number) - I would create a Politician class. Something like: class Politician(object): def __init__(self, name, ...


6

Imagine how much of a pain it would be to add another politician to this list. In addition to the Politician class suggested in another answer, I would suggest creating a list of Politicians and whenever you want to do something to one of them, iterate over this list. This may require adding a method to your Politician class. Then, adding another candidate ...


6

Before dealing with the "enter", "update" and "exit" pattern, which is specific to D3, I'd like to address some general issues first. Do not mix jQuery and D3: this mix is normally unnecessary. Not only that, it can make things fail silently. So, instead of: $("#click").on('click', function() { if (value == 'stack') { value = 'bar'; } else {...


6

Parser Your parser has a bug in line 62: raw = ''.join([n for n in file.readlines() if not n.startswith('>')]).replace('\n', "").lower() will concatenate all sequences, despite them potentially belonging to different DNA Sequences. Here is Wikipedia (the best source to cite xD): A multiple sequence FASTA format would be obtained by concatenating ...


6

It would be better to use GROUP by in your SQL. By this way you will get rid of long SQL query. SELECT Rating, COUNT(id) FROM list WHERE songID=:songID GROUP BY Rating;


5

The program consists of a pipeline of operations: breaking up the input file into lines parsing each line as a complex number updating the histogram vector writing out the PPM file The first step to optimizing the program is to measure how long each of these steps is taking. criterion is a great tool, but because it runs the test function multiple times ...


5

You can simplify the tedious else-ifs in generateRandomNumbers like this: public static int[] generateRandomNumbers(int amount) { int ranges[] = new int[10]; for (int i = 0; i < amount; i++) { int num = (int)(Math.random() * 100) + 1; ranges[Math.min(9, num / 10)]++; } return ranges; } Getting random numbers with Math....


5

Here is the updated solution with batching. I found that the request times out of the batch size is much larger than 1000, unfortunately and I'm not sure what causes that: import csv from py2neo import Graph import time def main(): f = "C:file_path/file.csv" graph = Graph("http://localhost:7474/db/data/") with ...


5

random.seed is a bug: add parentheses to actually call the function. Use collections.namedtuple so you can write member.fitness instead of the less readable member[0] copy.deepcopy should not be necessary in a functional approach Keeping the genes in a tuple instead of a list would make the member tuple fully immutable, in line with the functional approach. ...


5

Your method is doing to much. It is composing and displaying the output and calculating the histogram. This should be separated in more methods. What do we need for composing the output ? We need the Map<Integer, Integer> userHistogramInfo, the int[] definitionInBytes and the generated histogram. First we start and make the definitionInBytes a ...


5

Firstly, does the program give correct results? If so, how do you know? Without going into extensive unit testing, checking your results against a Matlab prototype/your Python implementation is probably good enough for now. I can't comment on the Gnuplot functions as I don't have it installed, also but some general C++ tips are... std::vectors are your ...


5

Given both the documentation of Python 3 contextlib or contextlib2, I’d say your usage is pretty standard for the tools at play. However, there is something bothering me a bit in your code: def get_histogram(self, name): """Return the histogram identified by name from the file. """ # The TFile::Get() method returns a pointer to an object stored ...


5

You don't need dfc, dfc.sort_index() and dfc.sort_values(time_col_str) both make a copy of the data. They don't perform an in-place sort. del dfc isn't needed, Python will perform that action at the end of the function anyway. Also I don't think it's doing what you think it's doing. I may be wrong, but since variables in Python are like names, when you're ...


4

Your output formatting is incorrect. First, you should not use spaces like this: System.out.println("BytesStored Number"); /* ... */ for (Integer key : keys) { /* ... */ System.out.println(key + " " + value); } One option would be to use tabs \t instead; however, that can have problems with variable-sized outputs, in ...


4

Janos' answer improves the random generator to something like public static int[] generateRandomNumbers(int amount) { int ranges[] = new int[10]; for (int i = 0; i < amount; i++) { int num = random.nextInt(100) + 1; ranges[Math.min(9, num / 10)]++; } return ranges; } but this is still far from sane. Without looking at how ...


4

janos has given you some nice hints about your random, and array indexing. I believe you should take it further, though. Specifically, your system should be parameterized. I would expect there to be three parameters: lowest number in random range largest number in the range size of the 'buckets' to partition the data in to. the number of samples to compute....


4

I have been facing the same issue for a few months, even though I didn't write that much functional code before switching. Please take my comments with a grain of salt even if I say "do this" instead of "this might help but I'm not sure". Use dictionaries instead of tuples: def create_member(genes): return {'sum': sum(genes), 'genes': genes} Use ...


4

Since you seem focused on functional programming, the main suggestion I'll have is regarding the use of arguments. It is recommended functions use all their arguments (see how step does not use x) and more importantly, that they only use variables that are either passed as arguments or defined inside their body (see how step uses possibleSteps that is ...


Only top voted, non community-wiki answers of a minimum length are eligible