indexing

Python – How can I move a nested json dictionary up to its own index?

Python – How can I move a nested json dictionary up to its own index? Question: I have a json dataset where each item/index can contain 2 nested dictionaries. The problem is that one of these nested dictionaries contains all of the exact key:value pairs as its parent dictionary. To put it in other words, …

Total answers: 2

Map the indices of 2d array into 1d array in Python

Map the indices of 2d array into 1d array in Python Question: Say I have a square 2d array (mat) and a 1d array (arr) which is the same length as the flattened 2d array (the values inside are different). Given the row and column index of the 2d array, how can I map it …

Total answers: 1

Index matrix but return a list of lists Pytorch

Index matrix but return a list of lists Pytorch Question: I have a 2-dimensional tensor and I would like to index it so that the result is a list of lists. For example: R = torch.tensor([[1,2,3], [4,5,6]]) mask = torch.tensor([[1,0,0],[1,1,1]], dtype=torch.bool) output = R[mask] This makes output as tensor([1, 4, 5, 6]). However, I would …

Total answers: 1

pandas fill a dataframe according to column and row value operations

pandas fill a dataframe according to column and row value operations Question: Let’s say that I have this dataframe: ,,,,,, ,,2.0,,,, ,2.0,,2.23606797749979,,, ,,2.23606797749979,,,2.0, ,,,,,2.23606797749979, ,,,2.0,2.23606797749979,, ,,,,,, I would like to get a two dimensional vector with values of the indexes and the columns of each element which is not nan. For example, in this case, …

Total answers: 1

Python np where , variable as array index, tuple

Python np where , variable as array index, tuple Question: I want to search a value in a 2d array and get the value of the correspondent "pair" in this example i want to search for ‘d’ and get ’14’. I did try with np location with no success and i finished with this crap …

Total answers: 3

Values in numpy matrix based on an array using index and value of each element

Values in numpy matrix based on an array using index and value of each element Question: I would like to use a numpy array to index a numpy matrix using the values of the array indicating the columns, and indices indicating the corresponding row numbers.As an example, I have a numpy matrix, a = np.tile(np.arange(1920), …

Total answers: 1

OpenCV Mat cpp operation only on condition

OpenCV Mat cpp operation only on condition Question: Having a hard time figuring out how to do this python operation in c++ without looping. The goal is to perform an operation only on a part of the cv::Mat that meets a condition. In this case, scaling values of the image that were originally between -5 …

Total answers: 1

How can I make this Indexing algorithm more efficient?

How can I make this Indexing algorithm more efficient? Question: I’ve got a Dataframe (deriving from a csv file with various columns) with 172033 rows. I’ve created a custom indexing function that blocks pairs of records that haven’t got similar ‘name’ attributes. The problem resides in the efficiency of the algorithm. Just to get to …

Total answers: 4

Print full pandas index in Jupyter Notebook

Print full pandas index in Jupyter Notebook Question: I have a pandas index with 380 elements and want to print the full index in Jupyter Notebook. I googled already but everything I’ve found did not help. For example this does not work: with pd.option_context(‘display.max_rows’, None, ‘display.max_columns’, None): print(my_index) Neither this works: with np.printoptions(threshold=np.inf): print(my_index.array) In …

Total answers: 2