multidimensional-array

Python – how to resize an array and duplicate the elements

Python – how to resize an array and duplicate the elements Question: I’ve got an array with data like this a = [[1,2,3],[4,5,6],[7,8,9]] and I want to change it to b = [[1,1,2,2,3,3],[1,1,2,2,3,3],[4,4,5,5,6,6],[4,4,5,5,6,6],[7,7,8,8,9,9],[7,7,8,8,9,9]] I’ve tried to use numpy.resize() function but after resizing, it gives [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]. I can use a for loop to put the numbers …

Total answers: 2

Concatenating images in a channel dimension from a for loop

Concatenating images in a channel dimension from a for loop Question: I have a path file with 13 different images (.tiff format) and I want to concatenate all of them into an array of (13, 224, 224). I am getting the shape for all the 13 values but I still struggling to get them into …

Total answers: 1

How to search through an array and remove items that don't match a certain critera

How to search through an array and remove items that don't match a certain critera Question: I’m new to python and currently trying to complete an assignment. I have tried searching for an answer in other places but I have found my specific issues anywhere. Basically the assignment is to create an ATM transaction log …

Total answers: 1

How to generate a 2d array forming a chequerboard without numpy?

How to generate a 2d array forming a chequerboard without numpy? Question: The problem is the following: chequerboard(n, m, offset_h, offset_w), all arguments >=1, returns an n by m chequerboard where each (region) is of size offset_h by offset_w, the top left cell is always filled, and only the right hand and bottom edge may …

Total answers: 2

How to create a 2D array in python forming a diamond?

How to create a 2D array in python forming a diamond? Question: I’m trying to produce an n by n full diamond using python, but I’m having trouble making it fully work. If n is even, the result is two hashes wide and one hash wide if n is odd. diamond(3) returns [[‘0’, ‘1’, ‘0’], …

Total answers: 3

Python 2D array not appending additions

Cannot append 2D array Question: I’m trying to create an eight-puzzle game solver, and I have a little problem. My states are being stored as grids(represented by 2D- lists). I am trying to keep track of every resulting state by appending to a succ_states list whenever a move is made by the computer. However, my …

Total answers: 1

Find row number of a certain index in a ndarray

Find row number of a certain index in a ndarray Question: I need to find the row and column number of a specific index/item in a ndarray. I found nothing to do this simultaneously, so I tried to achieve this separately. In the shown code I only had at least an idea how to do …

Total answers: 2

How to load multiple csv-files into xarray Dataset and concat along multiple dimensions?

How to load multiple csv-files into xarray Dataset and concat along multiple dimensions? Question: There is a similar question to mine, but the data has a different structure and I run into errors. I have multiple .dat files, that contain tables for different arbitrary times t=1,3,9,10,12, etc. The tables in the different .dat files have …

Total answers: 2

How can I update a 2d numpy array based on condition, but still using it absolute value?

How can I update a 2d numpy array based on condition, but still using it absolute value? Question: having the following function: def one_more_fix(matrix): height, width = matrix.shape for i in range(height): for j in range(width): if abs(matrix[i,j]) >= 180: matrix[i,j] = abs(matrix[i,j]) – 360 Example input and output: simple_matrix = np.array([ [179, 181, -182], …

Total answers: 1