numpy

Polars Series.to_numpy() does not return ndarray

Polars Series.to_numpy() does not return ndarray Question: I was trying to convert a series to a numpy array via .to_numpy() but unlike what the documentation shows i am not getting a ndarray out but a seriesview Running exactly the example in the documentation: https://pola-rs.github.io/polars/py-polars/html/reference/series/api/polars.Series.to_numpy.html s = pl.Series("a", [1, 2, 3]) arr = s.to_numpy() arr type(arr) …

Total answers: 1

Fractal dimension with the Mass-radius method

Fractal dimension with the Mass-radius method Question: I have some images for which I want to calculate the Mass-Radius dimension to determine the fractal characteristics in the image. Here is one of them : Ottawa.png: The mass dimension defines the relationship between the area located within a certain radius and the size of this radius …

Total answers: 1

Reshape a numpy array so the columns wrap below the original rows

Reshape a numpy array so the columns wrap below the original rows Question: Consider the following scenario: a = np.array([[1,1,1,3,3,3], [2,2,2,4,4,4]]) np.reshape(a, (4, 3)) Output: array([[1, 1, 1], [3, 3, 3], [2, 2, 2], [4, 4, 4]]) Desired output: array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) How can I reshape …

Total answers: 2

How to perform basic math on numpy ndarray

How to perform basic math on numpy ndarray Question: So, I have a numpy ndarray with dimensions (984, 1977, 2). What I want to accomplish is to have a numpy ndarray where I do basic math on the final values. So let’s say data is my ndarray. And data[0][0] equals to [72 46]. So I …

Total answers: 1

Numpy tests cannot parse version

Numpy tests cannot parse version Question: After forking the Numpy repository and setting up the dev container for it, I attempted to run python runtests.py -v but it returns the following error Building, see build.log… Traceback (most recent call last): File "/workspaces/numpy/setup.py", line 47, in <module> raise RuntimeError(f’Cannot parse version {FULLVERSION}’) RuntimeError: Cannot parse version …

Total answers: 3

restructure a 2D numpy array based on matching column values

restructure a 2D numpy array based on matching column values Question: I’m working with a data set with ~30 million entries. Each entry has a timestamp, an ID, a Description, and a value. The overall numpy array looks something like: [ [Time 1, ID 1, D 1_1, V 1_1], [Time 1, ID 1, D 1_2, …

Total answers: 1

Fill columns based on groups and conditions in another column

Fill columns based on groups and conditions in another column Question: Consider the below Pandas DataFrame df = pd.DataFrame({‘Make’: [‘Tesla’,’Tesla’,’Tesla’,’Toyota’,’Ford’,’Ford’,’Ford’,’BMW’,’BMW’,’BMW’,’Mercedes’,’Mercedes’,’Mercedes’,’Jeep’,’Jeep’,’Jeep’], ‘Type’: [‘Model X’,’Model X’,’Model X’,’Corolla’,’Bronco’,’Bronco’,’Mustang’,’3 Series’,’3 Series’,’7 Series’,’C-Class’,’C-Class’,’S-Class’,’Wrangler’,’Compass’,’Patriot’], ‘Year’: [2015, 2015, 2015, 2017, 2018, 2018, 2020, 2015, 2015, 2017, 2018, 2018, 2020,2020,2021,2020], ‘Price’: [85000, 90000, 95000, 20000, 35000, 35000, 45000, 40000, 40000, 65000, 50000, 50000, …

Total answers: 3

Degenerate root finding problem: get the first value for which f(x)>0

Degenerate root finding problem: get the first value for which f(x)>0 Question: Given a function f(x) that is zero for all values x less than a critical value c, and non-zero for values x>c. I want to approximate the critical value c using an optimization method. Because the function f(x) is expensive, I want to …

Total answers: 2

Unexpected uint64 behaviour 0xFFFF'FFFF'FFFF'FFFF – 1 = 0?

Unexpected uint64 behaviour 0xFFFF'FFFF'FFFF'FFFF – 1 = 0? Question: Consider the following brief numpy session showcasing uint64 data type import numpy as np a = np.zeros(1,np.uint64) a # array([0], dtype=uint64) a[0] -= 1 a # array([18446744073709551615], dtype=uint64) # this is 0xffff ffff ffff ffff, as expected a[0] -= 1 a # array([0], dtype=uint64) # what …

Total answers: 4

Trying to translate for loops into numpy matrix operation

Trying to translate for loops into numpy matrix operation Question: This is a bit of an odd question, but I am trying to improve the runtime of my code by losing the for loops and relying on numpy operations. I am still a beginner at handling numpy matrix operations, and I cant seem to translate …

Total answers: 1