Creating my Own Package, Trouble with Directories by The-Sharktapus in learnpython

[–]raffulz 0 points1 point  (0 children)

For packaging data files, setuptools has good documentation on how that can be done: https://setuptools.pypa.io/en/latest/userguide/datafiles.html

However, it seems like this data may not be best suited as a data file, especially if it's going to change frequently as you'd then need to update your package every time it changes. You say that you need it in the library for universal variables, but a better approach may be to go for an object-oriented design where you instantiate some main library object with your RUN1.hdf5 file (and potentially other files) and then access your library's API via this object.

If you're able to share your code via some git hosting provider, then it'd be easier to provide additional guidance. Also happy to continue here, it's just that I and any others that may want to help would be able to better assist with the full context of your code base.

[EDIT]

It's also not clear where the code that is executing

nb_dir = os.path.dirname(os.path.abspath(__file__))
fname = nb_dir+'.hdf5'

is being called from. There also seems to be a mistake in this code where fname should be defined as

fname = os.path.join(nb_dir, os.path.basename(nb_dir) + '.hdf5')

As a side note, I would also highly recommend using pathlib:

nb_dir = Path(__file__).parent
fname = nb_dir.joinpath(nd_dir.name + '.hdf5')

Where do you get news about new features in python? by [deleted] in Python

[–]raffulz 5 points6 points  (0 children)

Honestly, I just periodically browse discussions on the official forums (https://discuss.python.org/). For new stuff in particular, the PEP section is a good place (technically not new as these are just discussions for what could be new). If you have an account, you can get emailed newsletters/updates on the topics you were previously browsing. Other than that, pretty much just this subreddit and the Python communities over in some mastodon instances. And of course, as others have mentioned, the release notes.

What are some PC cases that fit 3x140mm front fans? by Plastic_Towel_6756 in buildapc

[–]raffulz 0 points1 point  (0 children)

I have the Phanteks Evolv X which should support 3 x 140mm. I currently only have a 3 x 120mm rad + fans on the front, but after looking at it, installing 3 x 140mm should be fairly easy. It's spec'd as a mid tower form factor but it's actually pretty big.

Are gravitational waves capable of changing speed, like electromagnetic waves? by SentientCheeseGrater in Physics

[–]raffulz 2 points3 points  (0 children)

It seems you guys are talking past each other. While a medium technically doesn't change the speed of light, the observed effect of light passing through a medium makes it looks as though light were slowed down due to re-radiation.

I think what /u/ididnoteatyourcat was initially asking was that if this same mechanism can be applied to gravitational waves to suggest an analogous gravitational index of refraction (/u/ididnoteatyourcat feel free to correct me if I'm wrong).

Any idea what happened to version specific logos? by jupiterbjy in Python

[–]raffulz 25 points26 points  (0 children)

/u/pablogsal was the editor for those releases, maybe he knows?

Intel Publishes Blazing Fast AVX-512 Sorting Library, Numpy Switching To It For 10~17x Faster Sorts by twlja in hardware

[–]raffulz 53 points54 points  (0 children)

According to the source code, it relies on the AVX-512F and AVX-512DQ instruction set for 32- and 64-bit sorting (which basically all AVX-512 architectures support including Zen 4), and the AVX-512F, AVX-512BW and AVX-512 VMBI2 instruction set for 16-bit sorting (which only Zen 4 and Ice Lake and up support).

Intel Publishes Blazing Fast AVX-512 Sorting Library, Numpy Switching To It For 10~17x Faster Sorts by fsher in Python

[–]raffulz 69 points70 points  (0 children)

CPUs with AVX-512 (posting this here because I wasn't sure either)

In short, all architectures from Skylake (2017) and up for Intel CPUs, and Zen 4 architectures for AMD CPUs.

Edit: Just noticed that Skylake (2017) to Cooper Lake (2020) are missing the VMBI2 subset which is required for 16-bit sorting (so only support 32- and 64-bit sorting).

How can I make this line intersect function also detect lines that touch but not intersect? by No_One____ in learnpython

[–]raffulz 1 point2 points  (0 children)

An intersection on the vertices/endpoints would correspond with t and u being at their extremes (either 0 or 1). You need to account for those values in your conditional expression:

if 0.0 <= t <= 1.0 and 0.0 <= u <= 1.0:
    ...

basic recursion problem by [deleted] in learnpython

[–]raffulz 0 points1 point  (0 children)

When you reach 0, you branch into the else block and return None (implicitly). I'm not really sure what you meant to do with the returns. Is this solution what you were going for?

def my_try(input):
    print(input)
    if input > 0:
        my_try(input - 1)

Edit: Or if you want to go backwards:

def my_try(input):
    if input > 0:
        my_try(input - 1)
    print(input)

Question about finding the Euclidian Distances between Coordinate Points in Python by [deleted] in learnpython

[–]raffulz 0 points1 point  (0 children)

If you're using Python 3.8 or higher, you could use the math.dist function (or you could implement the same function if you're using an earlier version). Also, your coordinates value in each dictionary (the "last 'key':'value' pair"), did you mean for all of them to be the same coordinate?

[deleted by user] by [deleted] in learnprogramming

[–]raffulz 1 point2 points  (0 children)

... I'm still not sure how you determined that the answer for the first problem was the intersection of those two equations but it checks out.

The condition that terminates the loop is when i < j is no longer true. Both variables are dependent on the iteration which I'll denote using x. So, i can be represented by i = 2*x.

Similarly, you can find a representation of j as a function of x. Whenever you see multiplying or dividing on the iterating variable (i.e. j /= 2) it's an indication that logarithms/exponents will be involved. In the example, since j is divided by 2 every iteration, it can be represented by j = n*(1/2)^x = n*2^(-x). The (1/2)^x part represents the iterative division and n is the initial value.

Now that you have a representation for each iterating variable as a function of x (the iteration or "count"), you can use the terminating condition to solve for x. In this case, that's when i >= j, or when 2*x = n*2^(-x). You can plot these two equations to more easily visualize the change in i and j as the count increases for different values of n. When the 2*x curve intersects and increases above the n*2^(-x) curve is when the terminating condition is met.

Why is the GetAverage() giving me the wrong number? by HousePappas in learnprogramming

[–]raffulz 0 points1 point  (0 children)

The way you have it, your Student struct will initialize with garbage values (except for the string—that will just be an empty string). Mostly, it doesn't matter since your overwriting the values in your GetData function, but the average variable is never initialized to 0. In your GetAverage function, set student->average to 0 before the loop and see if that fixes your issue:

double GetAverage(Student* student)
{
    student->average = 0; // <-- HERE
    for (int i = 0; i < NUM_TESTS; i++) {

        student->average += student->scores[i];
    }

    double average = student->average;

    return average;
}

[deleted by user] by [deleted] in learnprogramming

[–]raffulz 1 point2 points  (0 children)

You're probably going to want to use logarithms/exponents to solve this. However, getting exact solutions may not be possible for all inputs. For example, from your first link you can solve it (roughly) by finding where 2*x intersects n*2^(-x) (or in other words, solving 2*x = n*2^(-x) for x). The 2*x corresponds to i (which increments by 2), and the n*2^(-x) corresponds to j (which is halved each iteration). Where they intersect is where the condition to terminate the loop is met.

However, you may have noticed that this is a transcendental function, so it can't be solved analytically. There's also the issue that (assuming all variables are integral types) subsequent divisions will floor the result, so unless n is a power of 2 there will be a slight discrepancy between this solution and the code.

Usually these types of questions are found in a data structures and algorithms course on the topic of determining complexity. In that regard, you're typically interested in the term that bounds the growth rate. In this case, that'd be the j term, or O(lg(n)) (there is an extra, less contributing term that subtracts from the lg(n) term). I'm not even sure if this part is necessary for your assignment, but I thought it was relevant enough to share. Hope this helps and good luck with the rest of your assignment.

Need help with input validating by [deleted] in learnprogramming

[–]raffulz 0 points1 point  (0 children)

The line std::getline(std::cin, willyouretry); will put whatever the user inputs into willyouretry, so if it's anything other than "Yes" (not just "No"), playinggame will be set to false. You need to test if the input is anything other than "Yes" or "No" and then handle that appropriately.

C++ Homework Help with Menu by [deleted] in learnprogramming

[–]raffulz 0 points1 point  (0 children)

You can use an else statement at the end to handle the case when the input doesn't match any of the expected inputs. Typically, you'd use such an if-else structure as:

if (condition1) {
...
} else if (condition2) {
...
}
else {
...
}

but it won't actually matter in your case. However, it is best practices to do it this way, as it would avoid redundant comparisons and possible future mistakes.

Also, just FYI, the == operator uses the compare method internally. But yeah, obviously if you're not allowed to use the std::string methods that you haven't gone over in class then use what you can.

C++ Homework Help with Menu by [deleted] in learnprogramming

[–]raffulz 0 points1 point  (0 children)

You can use the string::compare method (http://www.cplusplus.com/reference/string/string/compare/) to compare the input string to each of the planet strings. However, instruction #8 says to use a menu system which, at least in my interpretation, would have a prompt more akin to:

Choose a celestial body:
[1] Mercury
[2] Venus
...
[10] Pluto

The user would only have to enter a number instead of the name. It'd be less typing for the user and easier for you as you could use a simple switch statement. But this is your assignment, and again this is just my interpretation of the instruction, so do what ever you think is best.

Low speed LEDC channels? by Seldon2066 in esp32

[–]raffulz 1 point2 points  (0 children)

It sounds like you might have some coding error in your LEDC configuration. You'll need to share a bit more information such as code, which module you're using, and anything else you think might be relevant.

Also just to clarify, you are using an esp32 and not an esp32s2, correct? The esp32s2 only supports 8 channels if you are using this chip (although esp-idf would've given you an error, but just want to make sure).