arrays

how to get a value from a string line of a file

how to get a value from a string line of a file Question: I have a log file which contains multiple lines and I want to get the value of the string WorkerThreads="20" from specific line of the below log content 10000 2aa0 03/29 17:02:30 ### Context="cvd.exe" Module="ThreadPool" Instance="cvstatanalysis" Type="Delta" TaskAdded="0" TaskDone="0" 10000 2aa0 03/29 …

Total answers: 1

How to run a Fortran script with ctypes?

How to run a Fortran script with ctypes? Question: First of all I have no experience coding with fortran. I am trying to run a fortran code with python ctypes. I used the command gfortran -shared -g -o test.so test.f90 to convert my test.f90 file (code below) to test.so. After reading C function called from …

Total answers: 1

Convert numpy 1D array to an adjacency matrix

Convert numpy 1D array to an adjacency matrix Question: How can I convert a numpy 1D array: np.array([1,2,3,4,5,6,7,8,9,10]) to an adjacency like matrix, i.e with zeroes in the diagonal? Desired output: [[0 0 0 0 0] [1 0 0 0 0] [2 5 0 0 0] [3 6 8 0 0] [4 7 9 10 …

Total answers: 2

where can I find the numpy.matmul() source code?

where can I find the numpy.matmul() source code? Question: I do not obtain the same results when I use np.matmul(A, b) in Python and when I use xtensor-blas‘s xt::linalg::dot(A, b) in C++. I am investigating the reasons, as when saved and read from disk, A and b are identical when doing np.allclose(A, b) in Python. …

Total answers: 1

Creating a curved array diagram without contours

Creating a curved array diagram without contours Question: So I have a python array and a code that produces a 2D representation of it: import numpy as np import matplotlib.pyplot as plt # Define the input data as a 2D NumPy array arr = np.array([ [‘x’, ‘x’, ‘x’, ‘y’, ‘y’, ‘z’, ‘z’, ‘z’, ‘z’, ‘z’, …

Total answers: 1

Taking the mean of a row of a pandas dataframe with NaN and arrays

Taking the mean of a row of a pandas dataframe with NaN and arrays Question: Here is my reproducible example: import pandas as pd import numpy as np df = pd.DataFrame({‘x’ : [np.NaN, np.array([0,2])], ‘y’ : [np.array([3,2]),np.NaN], ‘z’ : [np.array([4,5]),np.NaN], ‘t’ : [np.array([3,4]),np.array([4,5])]}) I would like to compute the mean array for each row excluding …

Total answers: 2

Select and/or replace specific array inside pandas dataframe

Select and/or replace specific array inside pandas dataframe Question: Here is my reproducible example: import pandas as pd import numpy as np df = pd.DataFrame({‘x’ : [np.zeros(2), np.array([1,2])], ‘y’ : [np.array([3,2]),0], ‘z’ : [np.array([4,5]),np.zeros(2)], ‘t’ : [np.array([3,4]),np.array([4,5])]}) My goal is to change np.zeros(2) to np.Nan so as to be able to compute the mean two-dimensional …

Total answers: 1

Is there a better way of printing my dice result in my dice roll function?

Is there a better way of printing my dice result in my dice roll function? Question: So I’m writing a dice_roll function for 2 dices to be rolled for my dice game project, currently I want to include the corresponding dice result in a dice format. Although the code does work, I was wondering if …

Total answers: 4

Remove entire array based on single item on list using regex

Remove entire array based on single item on list using regex Question: I have several list of lists (obtained from a for loop). Each one is composed like following: [[‘8.761,00’, ‘67.512,00’, ‘0,00’, ”, ”], [None, ”, ”, ”, ”], [”, ‘Dovuto’, ‘Pagato’, ‘Rimborsato’, ‘Debito/Credito’], [‘Soggettivo 15%’, ‘1.314,15’, ‘1.314,15’, ‘0,00’, ‘0,00’], [‘Integrativo 4%’, ‘2.700,48’, ‘2.700,48’, ‘0,00’, …

Total answers: 3