2d

non-iteratively turning a 2d numpy array into a 1d array, via an AND operation

non-iteratively turning a 2d numpy array into a 1d array, via an AND operation Question: i have a 2d numpy array of boolean values of shape(1E5, 2), with it acting like an array of x,y values. ie, 1E5 items each with 2 boolean values, being stored in that initial 2d array example: [ [True, False], …

Total answers: 1

make 3d numpy array using for loop in python

make 3d numpy array using for loop in python Question: I have training data with 2 dimension. (200 results of 4 features) I proved 100 different applications with 10 repetition resulting 1000 csv files. I want to stack each csv results for machine learning. But I don’t know how. each of my csv files look …

Total answers: 3

Python Summing A 2D Array In Steps Defined With Element Number Range

Python Summing A 2D Array In Steps Defined With Element Number Range Question: import Numpy as np a = np.array([[5, 1, 8, 1, 6, 1, 3, 2],[2, 3, 4, 1, 6, 1, 4, 2]]) n = 2 [(a[0:2, i:i+n]).sum(axis=1) for i in range(0,a.shape[1],n)] The output is: [array([6, 5]), array([9, 5]), array([7, 7]), array([5, 6])] How …

Total answers: 3

how can a write a 2-d array without any imports?

how can a write a 2-d array without any imports? Question: Anyone know how to write a 2d array? The result: [[0,1,0] [0,2,0] [0,3,0]] And with no imports or any library: a=[] for y in range (3): row=[] for x in range (3): row.append(0) a.append(row) I’ve come up this far. The answer should contain these …

Total answers: 2

2D List Minesweeper Task? [Python]

2D List Minesweeper Task? [Python] Question: I am trying to create a minesweeper where I create a function of a grid of # and – where each # is a mine and – is a mine-free spot, then return a grid where each dash is replaced by a digit indicating the mines around it . …

Total answers: 1

Problem with creating a pygame object inside a class

Problem with creating a pygame object inside a class Question: So this is the code that I created, it’s going to be a simple 2D game. I was trying to experiment with classes while making another game to make it more functional and organized. But the problem is that when I run the code and …

Total answers: 2

Shuffling two 2D tensors in PyTorch and maintaining same order correlation

Shuffling two 2D tensors in PyTorch and maintaining same order correlation Question: Is it possible to shuffle two 2D tensors in PyTorch by their rows, but maintain the same order for both? I know you can shuffle a 2D tensor by rows with the following code: a=a[torch.randperm(a.size()[0])] To elaborate: If I had 2 tensors a …

Total answers: 1

Improving the numpy functionality of a 2D cosine function

Improving the numpy functionality of a 2D cosine function Question: I have functioning code but I would like help on two aspects: Improve the numpy code so that the code runs faster (i.e. don’t use for loops) I would like to first ask about number 1. Here is the code snippet I am inquiring about: …

Total answers: 1