I’m working with a very large dataset in Python, so I’m trying to use histograms instead of arrays (the arrays get way too large for saving/loading/mapping). I’m crawling over a bunch of files and pulling information from them, and I would like to then take the information and remake the his…
Tag: numpy
Python implementation of Matlab Code – Finite Difference Method
Given this Matlab Code created by my teacher: I tried to implement this in Python by using this code: However when I run the code with the same inputs, I get different results when plotting them. My inputs: Python plot result compared to exact result. The x-es represent the actual solution, and the red line i…
Convert dictionary with coordinates and values to 2D array
Assume the next dictionary is given: In the dictionary above each key displays a point in the matrix (x, y) and a value displays the value found in the matrix. How could I construct an array that will contain the values located at each point x, y? According to the dictionary above the expected result is: Answ…
Python: get attribute from class objects stored in an array
I would like to get the attribute of every object contained in an ndarray. Consider the following code, where after vectorization the function returns an ndarray with the objects. From each of these objects in the array, I would like to get the attribute and store the attributes in a new array. The classes an…
Getting same result for different CSV files
DESCRIPTION: I have a piece of Python code, and this code takes a CSV file as input and produces a .player file as output. I’ve four different CSV files, hence, after running the code four times (taking each CSV file one by one), I’ve four .player files. REPOSITORY: https://github.com/divkrsh/grid…
How to find nearest point in segment in a 3d space
I am solving an algorithmic problem which sounds like this: Given a three-dimensional space and segments in it. Find the point with minimal distance to all of the segments. Example input: in the first line N – the number of segments, in the N next lines given the begin and the end of each segment: x1 y1…
Reading software-specific text file data into pandas dataframe
A software I use outputs the results as text txt files in the following way Output Text File. or like here for example: Now I want to analyse the results for each joint and dont know how to import the text file into pandas in a feasible way. Optimally I want something like this Wanted Format or a separate pan…
Replacing NaN values in a DataFrame row with values from other rows based on a (non-unique) column value
I have a DataFrame similar to the following where I have a column with a non-unique value (in this case address) as well as some other columns containing information about it. Some of the addresses appear more than once in the DataFrame and some of those repeated ones are missing information. If a certain row…
Intersection of two 2-D numpy arrays with unequal rows and columns
I have 2 arrays, one of shape (455,98) and a second with shape (182,472). A geometric description is as per the attached image. Is there a pythonic way to do this? I would also be happy to receive guidance on how to write a function to achieve this. Answer Don’t know if I understood your question comple…
More pythonic way of creating within-class scatter matrix
I am looking for a better way of calculating the following I would prefer getting rid of the for loops using numpy. This is the within-class scatter matrix for fischers linear discriminant. Answer You can write as follows: This is because sum_i x_i x’_i = X’ X, where X is (N, 3) matrix and x_i = X…