## [Solved] Read each line from file as numpy arrays in python

Issue I have a file 'test.txt' with 4 lines as below: [35,51,3701] , [10,6,7700.75] , [42,31,4700.5] , [31,41,1700.25] , [6,25,3901.25] , [10,12,3301.5] [4,13,3709.25] , [13,24,3761.5] [11,18,3101.25] , [26,7,3671] …

## [Solved] Filtering out rows in multidimensional numpy arrays

Issue Let's say that I have an array like this: array([[ 1 , 2 ], [- 1 , - 2 ], [ 0 , 0 ], [- 1 , 2 ], [ 2 , - 1 ]]) I want to filter out all rows that include negative numbers in them. An…

## [Solved] In Python, is it possible to return multiple 3D array slices all at once without a for loop?

Issue Here is example code. I want to find the way to run the last two lines at once and return the results in the same array all at once without concatenation, is this possible? import numpy as np arr = np.ones((3,3,3)) arr[…

## [Solved] Replace repeated values with counting up values in Numpy (vectorized)

Issue I have an array of repeated values that are used to match datapoints to some ID. How can I replace the IDs with counting up index values in a vectorized manner? Consider the following minimal example: import numpy as …

## [Solved] Simulating expectation of continuous random variable

Issue Currently I want to generate some samples to get expectation & variance of it. Given the probability density function: f(x) = {2x, 0 <= x <= 1; 0 otherwise} I already found that E(X) = 2/3, Var(X) = 1/18, my …

## [Solved] List of boolean numpy arrays from list of numpy arrays

Issue Consider a list of np arrays, x , with an arbitrary length and an arbitrary number of columns. As an example: import numpy as np np. random .seed( 0 ) random = np. random .randint( 0 , 3 , 100 ) x = [ random [ 0 : …

## [Solved] Numpy multiplication based on combinations of a list

Issue I have list of n numpy arrays and a list of corresonding names. An example: import numpy as np np.random.seed( 0 ) i = 3 x = [np.array(np.random.randint(- 1 ,high= 1 , size= 100 )).T for k in range (i)] names = [ &…