If I have a numpy array called data, for example:
[[ 3.6216 8.6661 -2.8073 -0.44699 0. ]
[ 4.5459 8.1674 -2.4586 -1.4621 0. ]
[ 3.866 -2.6383 1.9242 0.10645 0. ]]
and I want to get the last column, I can…
I have a function that eat a couple of seconds. The function should return the Top(n) colors in a given Image. The return must be sorted, so i could work with the rgb values from the first, second, third top most color.
On the fist hand i had an…
Suppose I have a lattice
a = np.array([[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3],
[4, 4, 4, 4]])
I'd like to make a function func(lattice, start, end) that takes in 3 inputs, where start and end are the…
How can I slice the last 2 columns of a numpy array?
for example:
A = np.array([[1, 2, 3], [4, 5, 6]])
and I want to get B as the last 2 columns of A which is [[2, 3], [5, 6]]
I know that I can index it from start of the array such as B = A[:, 1:3].…
I can index my numpy array / pytorch tensor with a boolean array/tensor of the same shape or an array/tensor containing integer indexes of the elements I'm after. Which is faster?
I have a 4-D NumPy array, with axis say x,y,z,t. I want to take slice corresponding to t=0 and to permute the order in the y axis.
I have the following
import numpy as np
a = np.arange(120).reshape(4,5,3,2)
b = a[:,[1,2,3,4,0],:,0]
b.shape
I get…
I have 4 PyTorch tensors:
data of shape (l, m, n)
a of shape (k,) and datatype long
b of shape (k,) and datatype long
c of shape (k,) and datatype long
I want to slice the tensor data such that it picks the element addressed by a in 0th…
I'm trying to generate two numpy arrays from one. One which is a slice slice of an original array, and another which represents the indexes which can be used to look up the values produced. The best way I can explain this is by example:
import numpy…
I have the following array:
arr = np.array([[1, 1, 1, 1, 1, 1],
[2, 0, 0, 0, 0, 2],
[3, 0, 0, 0, 0, 3],
[4, 4, 4, 4, 4, 4]])
inverse_slice = arr[1:3, 1:5]
I want to update the values of all values in the array,…
I have a complex nested structured array (often used as a recarray). Its simplified for this example, but in the real case there are multiple levels.
c = [('x','f8'),('y','f8')]
A = [('data_string','|S20'),('data_val', c, 2)]
zeros = np.zeros(1,…
I have 4D data in a data frame. I need to convert it to 3D Numpy array. I can do it with for-loops, but is there more efficient way?
# Data:
df = pd.DataFrame()
df['variable'] = ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D', 'A',
…
Consider some array arr and advanced indexing mask mask:
import numpy as np
arr = np.arange(4).reshape(2, 2)
mask = A < 2
Using advanced indexing creates a new copy of an array. Accordingly, one cannot "chain" a mask with an an additional mask or…
I have two numpy array matrix A and B of length 32 and shape (32, 32, 3) each . I want to combine them into a new array so that the dimensions of my new array is (2, 32, 32,3).
Using np. concatenate is throwing an error.
I am having the following array
import numpy as np
T = np.array(([1,-1,0,0,0,0],
[3,0,5,0,0,0],
[0,-1,0,9,0,0],
[0,0,0,0,-2,1],
[3,1,0,0,2,0],
[1,-2,1,0,2,2]))
I want to remove…