arrays

I need to insert a numpy array of a different shape than my other arrays

I need to insert a numpy array of a different shape than my other arrays Question: I am currently trying to insert an array of shape (640, 1) inside an array of shape (480, 640, 3) to obtain a 481×640 array where the first column is juste a line of 640 objects and the other …

Total answers: 2

Is there a more efficent way of "expanding" a numpy array?

Is there a more efficent way of "expanding" a numpy array? Question: An algorithm requires me to add an additional variable into a square matrix, this results in adding a row and column to the matrix. I can use the np.insert method as shown below, but was wondering if there was a better way to …

Total answers: 1

Issue with 2D array in python

Issue with 2D array in python Question: I am working on a text-based chess project in python, and I have set up a pretty nice looking chess board in my output console. But whenever I try to place a piece somewhere, it fills up the entire file. The code I used is here: import os …

Total answers: 2

Write array to .txt-file

Write array to .txt-file Question: In Python I need to write a list of numpy-arrays (see attached picture) to a txt.-file and then reuse that original list of arrays in a new python-file. How can I do that? read_files = open("read_files.txt","w+") content = str(df) read_files.write(content) read_files.close() Then in the new python-file I did: file = …

Total answers: 1

How do I make my code discern how to divide my array?

How do I make my code discern how to divide my array? Question: I have to read this line from the text file: Asta Ieva 5 0 17 10 23 23 The first two words are a name, all the others are different numbers. How do I make it so that that my program creates …

Total answers: 1

How could I pair up x and y generated by np.meshgrid using python?

How could I pair up x and y generated by np.meshgrid using python? Question: I’m trying to generate a 2-dim coordinates matrix using python. I’m using x=np.linespace(min, max, step) y=np.linespace(min, max, step) X, Y = np.meshgrid(x, y) to generate x and y coordinates, where X like: [[0. 1. 2. 3. 4.] [0. 1. 2. 3. …

Total answers: 2

numpy get start, exact, end of convergence

numpy get start, exact, end of convergence Question: I have a numpy array of floats: […, 50.0, 51.0, 52.2, …, 59.3, 60.4, 61.3, 62.1, …, 67.9, 68.1, 69.2, …] You can see that the numbers are first converging to 60, and then diverging from it. There is a range: from 52.0 to 68.0; in the …

Total answers: 2

Applying function to 2 vectors to obtain a 2D matrix

Applying function to 2 vectors to obtain a 2D matrix Question: My question is exactly the same as this one but in Python instead of R. I couldn’t find a similar question for python and so I’m asking this one. I have 2 vectors (lists actually) a = [1,2,3] b = [5,6,7] A defined function …

Total answers: 1

Finding indexes of elements in nested arrays

Finding indexes of elements in nested arrays Question: I have an array arr = [[[1, 2], [3, 4]], [5, 6]]. I am looking for a function f that returns me the indexes of the elements also in the nested array given only arr as input. For example, function(arr, 2) -> (0, 0, 1) Has some …

Total answers: 1