15
votes
Create a words histogram of a given string in python
str.split method without arguments
It does the same filtering as you do. Just skip ' ' argument.
list(dict.fromkeys(list comprehension))
It looks overburdened, right? You can create a set of list ...
13
votes
Accepted
Histogram word counter in Python
Several things can be improved in your existing code. First and foremost being, replacing your usage of re module. Regex matching is very heavy. You have a defined ...
11
votes
Get histogram of bytes in any set of files in C++14
This key loop looks incorrect:
while (!stream.eof() && stream.good()) {
unsigned char ch;
stream >> ch;
histogram[ch]++;
}
If ...
10
votes
Accepted
An ASCII histogram of a die rolled n times
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 ...
8
votes
Sparse 3D binning/histogram function
Some suggestions:
Passing the code through at least one linter such as flake8 or pycodestyle will make for more idiomatic and therefore readable code.
Do you have any automated tests? If so, do they ...
8
votes
Python 3.6 Dice Histogram
Various small comments:
you can write a[x+y] += 1
you always call random.seed with the same input so you'll always have the ...
8
votes
Accepted
Populating a structure
A case cursor == NULL does not free(out->data).
A test i > 1 is strange, and buggy. If ...
8
votes
Query to plot a histogram of song ratings
It would be better to use GROUP by in your SQL. By this way you will get rid of long SQL query.
...
8
votes
Accepted
Draw a histogram of the characters in input
That's some surprisingly compact but still very readable code! Very good use of C++20's ranges.
Casting numbers
You are performing several explicit casts. While I don't think there is anything wrong ...
8
votes
Accepted
Histogram manipulation
profiling
This submission is about performance,
yet it includes no profiling measurements.
All we are told is that hist() completes
within 44 msec.
temporal ...
7
votes
Accepted
Turning a grayscale image into a histogram of the intensity of the pixels of that image
JPG vs PNG
Somehow, your code seems to produce wrong results with the above JPG. When used with the same image converted to PNG, the histogram looks much better, and much closer to what Photoshop ...
7
votes
Accepted
Get histogram of bytes in any set of files in C++14 - take II
The code looks much improved compared to version 1. Most of what I have to say may be subjective preference rather than required actions.
I'll step through the code in sequential order, rather than ...
6
votes
Populating a structure
One additional problem is that the memcpy is not copying all the data. It is copying ds bytes, not ...
6
votes
Accepted
Reading and processing histograms stored in ROOT files
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:
...
6
votes
Accepted
Detecting if image taken by camera is too dark
Intelligibility
I can't quite work out what's going on with the main loop.
...
6
votes
Accepted
Sparse 3D binning/histogram function
Since you don't care about the distinct values, only the sum in each bin, you can avoid one of these for loops:
...
6
votes
Draw a histogram of the characters in input
C++20 ranges and views are not available for all compilers yet. The default C++ compiler on Ubuntu 22.04 does not support them because it is gcc11 and not gcc12.
Since the problem is in the first ...
5
votes
Histogram word counter in Python
In addition to hjpotter92's answer you can improve your counting using dict.get()
...
5
votes
Accepted
Image processing and plotting
Usually, when using for loops and numpy together, you’re probably doing it wrong.
Some things you could replace in your code:
Use ...
5
votes
Detecting if image taken by camera is too dark
Sampling: Don't process ALL pixels
The speed mainly depend on the number of operations, in our case, pixels. And a lot of pixels. This means that the larger the image is, the slower your code will ...
5
votes
Accepted
K&R 1-14 - Histogram
Bugs.
The loop printing the histogram lines for numbers,
for(int i = 0; i <= 10; ++i)
lets i become 10, which accesses <...
5
votes
Turning a grayscale image into a histogram of the intensity of the pixels of that image
I have some suggestions for your code.
Extract the expression to variables when used multiple times.
In your code, you can extract the similar expressions into variables; this will make the code ...
5
votes
Accepted
Print a character frequencies as a vertical graph
This is a pretty good start. You should be warned that K&R describes a very early version of C, and the language has evolved considerably since the 1980s.
For example, we normally always write ...
5
votes
Accepted
K&R "The C Programming Language" exercise 1-13: histograms
for (int j = (c = putchar('\n')) - c; is too clever to be good. You save one line of vertical space by the price of a reviewer's mental effort. Don't do this. Be ...
5
votes
Histogram manipulation
There is one major issue with the code, and then some performance issues (the other answer already touched on some of these).
Major Issue
In the histogram computation, you loop over pixels in parallel,...
5
votes
Get histogram of bytes in any set of files in C++20
It's got all my suggestions incorporated (apart from a late edit to recommend std::uint_fast64_t from <cstdint> instead of ...
4
votes
Find maximum area of rectangles within a histogram
Implementation
It's not clear why you defined a class with no data members and only one function member. This would be much simpler as a plain function.
The various commented-out assignments to ...
4
votes
Print the frequency of characters as a horizontal histogram
You have assumed that the input character coding is ASCII, but the C standard allows other codings (notoriously EBCDIC) that use different numbers for the printable characters.
Even with only ASCII-...
4
votes
Accepted
Histogram of letters in string
You've got way too many comments - you should only use comments when you need to explain an oddity. You don't need a comment to tell you when a method ends. I know this for loop for string.length() is ...
4
votes
Accepted
Finding the 20th percentile pixel of an image using a histogram instead of std::sort
Well, index=std::floor(0.2*(srcSor.size())/100 is equivalent to the much simpler index = srcSor.size() / 500, ignoring some ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
histogram × 65data-visualization × 16
c × 15
python × 13
beginner × 13
c++ × 12
java × 11
file × 8
performance × 5
image × 5
matplotlib × 5
python-3.x × 4
strings × 3
numpy × 3
c++14 × 3
io × 3
opencv × 3
byte × 3
c# × 2
algorithm × 2
php × 2
python-2.x × 2
haskell × 2
functional-programming × 2
rust × 2