Skip to content
Advertisement

Tag: arrays

Find whether 1D sub-array is in 2D array

I have a data-array like: It has about 4000 pairs in it, but typically fewer on the order of a few hundred. I need to find whether a two-valued array already exists in this large data-array, eg. does [1,1] exist in the array? So the function I need should act something like this: I couldn’t get the numpy functions isin()

All permutations of an array in python

I have an array. I want to generate all permutations from that array, including single element, repeated element, change the order, etc. For example, say I have this array: And if I use the itertools module by doing this: Or using loop like this: I only get: But what I want is: The result is all permutations from the array

python iterate over arrays matrices

I am trying to create a new matrix(array) where I have been scouring the documentation in numpy but can’t find a function to satisfy this. Answer You’re looking for numpy.matmul. You’ll need to make the vectors have two dimensions (with a size of one in one of the dimensions). For example:

The sum of the products of a two-dimensional array python

I have 2 arrays of a million elements (created from an image with the brightness of each pixel) I need to get a number that is the sum of the products of the array elements of the same name. That is, A(1,1) * B(1,1) + A(1,2) * B(1,2)… In the loop, python takes the value of the last variable from

How do i remove a specific json value in python?

I’m making a playlist website that can create display and delete playlists and songs. I’m using a JSON file to store the data. The only feature that isn’t working is the delete song feature. This is my JSON file I’m using the ID of the playlist and the index of the song to locate it in the list and using

Initializing a class with numpy array question

So I have defined the following function to be entered into a class: Which works exactly how I want it to, taking in a numpy array as argument, and produces a simpler matrix as a numpy array. Now, I would like to define a class that is initialized by a numpy array, and once I enter a matrix into the

Find match of numeric arrays Python

Consider I have 2 arrays. arr2 will always be longer than arr1. I’d like to drop the values from arr2 to best fit arr1. If arr2 doesn’t have an equal value to arr1 it will need to be the closest value that is still in arr2. observing the output. the first value is 0, both have a match at the

Dynamically changing a list while looping

I have a list: what I would like to do is loop though this list but then change the list. Basically when I loop through nums = [0, 1, 2, 3] nums would need to change to: Is there a way of changing nums like this? I feel like there is a simple solution to this, but I’ve been stumped

NumPy array row differences

I have a NumPy array vectors = np.random.randn(rows, cols). I want to find differences between its rows according to some other array diffs which is sparse and “2-hot”: containing a 1 in its column corresponding to the first row of vectors and a -1 corresponding to the second row. Perhaps an example shall make it clearer: then I can compute

Advertisement