arrays

Coverter the type in the array

Coverter the type in the array Question: how to convert to the form like me in the example below: ex: [a, b, c,d ] >> [(a,b) (c,d)] [a,b,c,d] #wish to be like this [(a,b) (c,d)] Thanks Asked By: Quan Tran || Source Answers: Try this; l = [‘a’,’b’,’c’,’d’] n = 2 lst = [] for …

Total answers: 1

Sorting a list of arrays and one value in pandas

Sorting a list of arrays and one value in pandas Question: I’m trying to sort a list which is set up like list=([set of coordinates], euclidean distance of route between those coordinates. I want to sort the list by the shortest coordinates. One list looks like this (via print(*sortedList, sep = "n")): ([(1.0, 7.0), (4.0, …

Total answers: 2

Allocate array with values and indices from other arrays

Allocate array with values and indices from other arrays Question: I have 2 arrays, one with values and the other with indices. Can I populate another array (with different dimensions) using these two in numpy? vals = [[0.7, 0.7, 0.2, 0.1], [0.3, 0.2, 0.1, 0.1]] indices = [[2, 5, 6, 8], [0, 1, 2, 7]] …

Total answers: 1

Find the index value of similar items in array

Find the index value of similar items in array Question: I created a for loop that will pinpoint the location when name and DB are the same value. The problem is if there is a value that is not present in name, the index becomes -2, and will be -2 for the rest of the …

Total answers: 3

Setting Values in an Multidimensional numpy Array with Indexes

Setting Values in an Multidimensional numpy Array with Indexes Question: i am searching for an elegant and efficient way to initialize a 3dimensional numpy array that is all zeros but for a specific row. E.g. empty = np.zeros((3,3,2)) row_indexes = np.array([1,1,0]) replacement = np.array([[1,2][3,5][5,6]]) # intended outcome: [[[0 0] [1 2] [0 0]] [[0 0] …

Total answers: 1

How to efficiently filter a large python list?

How to efficiently filter a large python list? Question: I have a relatively large array called allListings and want to filter out all rows where allListings[:][14] == listingID. This is the code I am using: tempRows = list(filter(lambda x: x[14] == listingID, allListings)) The filtering is repeated in a for loop for all different listingID …

Total answers: 2

How do I add bytearrays to doctests?

How do I add bytearrays to doctests? Question: This is my function signature, def fun12(bytes_var: bytearray, signed: bool) -> (int): When I do, print(fun12(b’x00x10′,False)) My code works just fine, but when I have something like the following in my doctest comments, >>> fun12(b’x00x10′,False) 16 I get an error, Failed example: fun12(b”,False) Exception raised: Traceback (most …

Total answers: 2

Create a new numpy array from elements of another numpy array

Create a new numpy array from elements of another numpy array Question: I’ve been strugling to create a sub-array from specific elements of a first array. Given a first array that looks like this (it commes from a txt file with two lines : L1,(B:A:3:1),(A:C:5:2),(C:D:2:3) L2,(C:E:2:0.5),(E:F:10:1),(F:D:0.5:0.5)): code toto = pd.read_csv("bd_2_test.txt",delimiter=",",header=None,names=["Line","1rst","2nd","3rd"]) matrix_toto = toto.values matrix_toto result …

Total answers: 1