Skip to content

Tag: numpy

Convert List of list into tuple of tuples

I have a list of 2×1 matrices like: I need to convert it into a tuple of tuples, like: I know I can loop through the list and convert it manually , trying to check if there is a better-optimized way of doing it. Answer You can do it this way using numpy indexing and slicing that outer dimension. Output:

Numpy insert matrix values with matrix index

I have the following code which creates a 4D grid matrix and I am looking to insert the rolled 2D vals matrix into this grid. If vals would be a 1D array and I would use a 1D insert_map array as a reference it would work, however using it in multiple dimensions seems to be an issue and it raises

2D Vectorization of unique values per row with condition

Consider the array and function definition shown: The point of the function is to return the rows of array a that have exactly grpCount groups of elements that each hold exactly grpSize identical elements. For example: As expected, the code outputs out = [[2, 2, 5, 6, 2, 5], [3, 3, 7, 7, 3, 3]]. The 1st outpu…

Eucledian distance to point source

I am stimulating a model via a point source, which is located above (z-direction)– to be able to compute the impact of the stimulation i need to compute the eucledian distance from this point power source to each mid of compartment (see picute). I tried it this way, but the results are strange — m…

Getting the minimum indexes with numpy Python

I am trying to get the index values of the function. But I want to get the minimum instead of the maximum values of just like the post: post. I have tried to convert the function below to work for the minimum values unlike the maximum values to getting the indexes. Max Values: Index Function Answer For the mi…