Skip to main content

All Questions

Tagged with
5 votes
1 answer
110 views

Efficient way to delete columns and rows from a numpy array using slicing and not np.delete

Would it be possible given an array A, bad row indices and bad column indices to use slicing to make a new array that does not have these rows or columns? This can be done with np.delete as follows: ...
KyroHere's user avatar
  • 107
1 vote
0 answers
55 views

Why is an array variable not getting updated unless assigning to [:]? [duplicate]

I was solving this leetcode problem of rotating the array right by k places and this is the function I wrote in Python: class Solution: def rotate(self, nums: List[int], k: int) -> None: ...
Aditya Raj's user avatar
-3 votes
1 answer
103 views

How to Slice Multi Dimensional Array?

Dipping my toes into multi dimensional array slicing in Python and am hitting a wall of confusion with the following code # Example 2D array matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # ...
chilly8063's user avatar
1 vote
1 answer
60 views

How to split an array using its minimum entry

I am trying to split a dataset into two separate ones by finding its minimum point in the first column. I have used idxmin to firstly identify the location of the minimum entry and secondly iloc to ...
John278's user avatar
  • 25
1 vote
1 answer
78 views

Adding numpy arrays to cells of a pandas DataFrame depends on initialisation

I was trying to add a list of numpy arrays as elements to the pandas DataFrame: DataFrame using: df.loc[df['B']==4,'A'] = [np.array([5, 6, 7, 8]),np.array([2,3])] Whether or not this is allowed seems ...
Anita Karsa's user avatar
0 votes
2 answers
129 views

Extract multiple roi's from np array using indices ranges without loops

I have a numpy array of shape 640 x 480: np.ones((640, 480)), and I have a min, max ranges for the rows, columns: u_min=[497, 157, 493, 137, 567] v_min=[ 36, 46, 208, 412, 418] u_max=[502, 162, 498,...
bhomaidan90's user avatar
1 vote
2 answers
84 views

Shapes of arrays obtained by mixed basic and advanced indexing in NumPy ndarray

Here is the code: import numpy as np x = np.arange(2*32*32*8*16) x = x.reshape(2, 32, 32, 8, 16) print("x-shape=", x.shape) y = x[0, 3:5, 8:10, [1, 2, 3, 4, 5], :] z = x[0][3:5, 8:10, [1, ...
Locutus's user avatar
  • 11
1 vote
1 answer
39 views

How do I slice a 2D numpy array using another 2D numpy array that contains indices?

I have a sparse matrix A that is of size (3000,3000), and I have another matrix B that is of size (83068, 2) that contains the indices of the non-zero elements of A. Is it possible to get a resulting ...
itsanhtuanho's user avatar
0 votes
1 answer
120 views

Select some specific columns in a 4D Numpy array

I'm trying to select a specific number of columns in a 4D array but apparently the way to do this is different compare to 3D arrays, example: numpy_vector = np.arange(0,120,dtype=np.int8) numpy_tensor ...
Michael995's user avatar
0 votes
1 answer
82 views

Can you slice a numpy 2D array with start and stop rules not at an index but at values greater than 1?

I have turned a geotiff LiDAR elevation surface into a numpy array by the below code: example_array = np.array(geotiff_surface) The array is hundreds of values by hundreds of values but could be ...
Patstro's user avatar
  • 69
0 votes
1 answer
78 views

NumPy Nearest Neighbor Line Fitting Across Moving Window

I have two two-dimensional arrays loaded into NumPy, both of which are 80i x 80j in size. I'm looking to do a moving window polyfit calculation across these arrays, I've nailed down how to conduct the ...
TornadoEric's user avatar
1 vote
1 answer
60 views

How to find the maximum/minimum offset in np.diagonal()?

I want to get back all the diagonals of a numpy matrix in the form of a list and np.diagonal() does that but slice notation doesn't work on it. I tried using slice notation, thinking by just putting a ...
Turtleishly's user avatar
2 votes
1 answer
707 views

How to use tuples as slice start:end values [duplicate]

I need to slice array with arbitrary dimensions by two tuples. I can use slicing, such as a[1:3, 4:6]. But what do i do if 1,3 and 4,6 are tuples? While a[(1, 3)] works, I tried a[(1, 3), (4, 6)] and ...
Ford F150 Gaming's user avatar
0 votes
1 answer
316 views

xarray dataset extract values select

I have a xarray dataset from which I would like to extract points based on their coordinates. When sel is used for two coordinates it returns a 2D array. Sometimes this is what I want and it is the ...
3dSpatialUser's user avatar
-1 votes
2 answers
81 views

Masking an array

I am trying to mask an array (called dataset) in python: The array has the following size (5032, 48, 48). Basically these are 5032 48x48 images. But some of the images may not contain any data, so ...
user21045076's user avatar

15 30 50 per page
1
2 3 4 5
24