I have data stored in a NumPy structured array where part of the information identifies various cases. I would like to find the row that matches a given case. E.g., let’s say I’m storing the name of a building, room number, and the number of chairs and tables in the room in a (2,) array. This would then look something
Tag: numpy
Calculate delta in dictionary of dictionary
I have a dictionary of dictionaries which hold list of tuples like this: I would like to calculate the delta of the third items (which their first two items are identical) in each tuple inside of the dictionaries, between each week (e.g., week1 and week2,.. week19 and week20)and put them as new dictionaries in the main dictionary. So my desired
How to do Linear Regression and get Standard Deviation (Python)
I have this very simple problem, but somehow I have not found a solution for it yet: I have two curves, A1 = [1,2,3] A2 = [4,5,6] I want to fit those curves to another curve B1 = [4,5,3] with Linear Regression so B1 = aA1 + bA2 This can easily be done with sklearn LinearRegression – but sklearn does
Filter a numpy ndarray using another numpy ndarray
I have two numpy ndarrays of the same shape (15081, 56724, 3, 3). What I want to do is as follows: Say we have a cross section of the first array, array1[1, 1, :, :], looks like this: I want to convert it to a boolean in a way that the max of each row is True and the rest
How to make a nxn filter to perform custom opertions in image array?
I am working with various images and I wanted to implement a method but I have no idea where to start. So I am looking forward to some suggestions. My idea as a method is to take an image array and after selecting a region of interest and then we say the selectedROI is 10×10 region of pixels as a
add random elemnt from list to existing dataframe string
I have a dataframe. df[‘Skill’]=python, sql, java. Now for each string I want to add random element (high, low, medium). For Eg: df[‘Skill’]=python:high, sql:low, java:medium. I have tried one code but it adds score[‘low’, ‘high’, ‘medium’] at the end of the string. Can someone please suggest how can i do it. Output: But i want is python: low, java: high,
Clustering on Python and Bokeh; select widget which allows user to change clustering algorithm
I am trying to build a feature in a Bokeh dashboard which allows the user to cluster data. I am using the following example as a template, here is the link:- Clustering in Bokeh example Here is the code from this example:- The example allows the user to cluster data. Within the code, you can specify which algorithm to use;
Replace pixel value in RGBA numpy array
I have a 2D array of RGBA values (Ex: [30, 60, 90, 255]) and I want to replace all white [255 255 255 255] with [0 0 0 0]. What is the simplest way to do this? Using for loops I have tried assigning a new array to an index but the index does not change: Answer You can use
Remove and add values to ​numpy array
Is there a more efficient way to remove the 0 from the beginning and insert the 20 at the end and retain the shape (1, 20)? Output: Answer You can just select a subset of the current array excluding the first element and then add 20 or whatever scalar you want at the end.
Enhancing my code that calculates Slope Sign Change (SSC)
I am trying to code this Slope Sign Change (SSC) formula: My attempt below seems to be missing something since it generates -2 instead of 1. I am really stuck in this. Your help is highly appreciated. Answer You can compute the temporal difference with np.diff as you did: x_{n} – x_{n-1} with np.diff(x, prepend=1)[1:-1] or with slicing: x[1:-1] –