Skip to main content

All Questions

Tagged with
2 votes
2 answers
60 views

Pandas: Fill in missing values with an empty numpy array

I have a Pandas Dataframe that I derive from a process like this: df1 = pd.DataFrame({'c1':['A','B','C','D','E'],'c2':[1,2,3,4,5]}) df2 = pd.DataFrame({'c1':['A','B','C'],'c2':[1,2,3],'c3': [np.array((...
cbw's user avatar
  • 289
-1 votes
0 answers
33 views

Efficiently Finding the Indices of the N Largest Values in a NumPy Array Without Sorting the Entire Array [duplicate]

I'm working with very large NumPy arrays (millions to billions of elements) and need to find the indices of the N largest values in the array. Using np.argsort() followed by slicing to get the last N ...
rysch's user avatar
  • 96
0 votes
1 answer
66 views

Apparently weird condition on inclusion of endpoint in np.arange() [duplicate]

The numpy.arange function takes the three parameters: start, stop, step (positional args.) The default step is 1. Throughout my entire Numpy experience, the last element of the resultant array is not ...
VizDracViz's user avatar
2 votes
1 answer
103 views

Why do these nearly identical functions perform very differently?

I have written four functions that modify a square 2D array in place, it reflects half of the square array delimited by two sides that meet and the corresponding 45 degree diagonal, to the other half ...
Ξένη Γήινος's user avatar
4 votes
1 answer
171 views

Efficient and readable way to get N-dimensional index array in C-order using NumPy

When I need to generate an N-dimensional index array in C-order, I’ve tried a few different NumPy approaches. The fastest for larger arrays but less readable: np.stack(np.meshgrid(*[np.arange(i, dtype=...
Olibarer's user avatar
  • 383
2 votes
2 answers
66 views

Numpy- strange behaviour of __setitem__ of array

Say we have an array: a = np.array([ [11, 12, 13], [21, 22, 23], [31, 32, 33], [41, 42, 43] ]) a[[1, 3], [0, 2]] = 0 So we want to set zeros to 0th and 2nd element at both 1st and ...
IzaeDA's user avatar
  • 397
1 vote
1 answer
47 views

Pandas dataframe assign nested list not working

I'm trying to assign a dataframe cell with a nested list: df.loc['y','A'] = [[2]] However, the actual assigned value is [2]. It works expected for [2], [[[2]]], [[[[2]]]], but just not for [[2]] See ...
Jian Wang's user avatar
1 vote
5 answers
98 views

Can I multiply these Numpy arrays without creating an intermediary array?

This script: import numpy as np a = np.linspace(-2.5, 2.5, 6, endpoint=True) b = np.vstack((a, a)).T c = np.array([2, 1]) print(b*c) produces: [[-5. -2.5] [-3. -1.5] [-1. -0.5] [ 1. 0.5] [ ...
Paul Jurczak's user avatar
  • 8,235
1 vote
3 answers
122 views

numpy element-by-element subtract

I have two numpy 'arrays': 1st is a 2D array with shape (N, 2) 2nd is a 3D "matrix" with shape (N, M, 2) where M can be different from 0 to N-1 Code example import numpy as np a = np.array([...
Arno Kukk's user avatar
2 votes
3 answers
221 views

What is the fastest way to generate alternating boolean sequences in NumPy?

I want to create a 1D array of length n, every element in the array can be either 0 or 1. Now I want the array to contain alternating runs of 0s and 1s, every full run has the same length as every ...
Ξένη Γήινος's user avatar
0 votes
0 answers
104 views

FAISS.from_texts() occur ValueError: input not a numpy array

vec_multi = embedding.embed_documents(pdf_chunks) import numpy as np vec_np = np.array(vec_multi) print(vec_np.shape) # (문장 개수, 임베딩 차원) print(vec_np.dtype) (2119, 768) float64 ...
jeonghyeon's user avatar
0 votes
2 answers
77 views

Processing satellite conjunctions with numpy efficiently

Original Post: How to populate a 2-d numpy array with values from a third dimension? New Post: I'm trying to analyze interference between satellites using numpy and sgp4 python libraries, and want to ...
SPZHunter's user avatar
0 votes
1 answer
54 views

Most efficient way to allocate n copies of an array to n-new dimensions?

The task is to create 361x721x11 copies of ll as fast as possible preferably using the functions in numpy. The following code works ll = ones((13,25)) # used ones() for illustration purposes. My real ...
Researcher R's user avatar
1 vote
1 answer
88 views

How to populate a 2-d numpy array with values from a third dimension?

New Post: Processing satellite conjunctions with numpy efficiently Original Post: I have a numpy array of shape n x m x r, where the n axis represents an object, the m axis represents a timestep and ...
SPZHunter's user avatar
0 votes
2 answers
80 views

Shortest way to broadcast 1d array to specific dimension in NumPy

I often find myself to broadcast 1d arrays into a specific dimension dim_a given a total number of dimension dim_total. What I mean is the following: import numpy as np a = np.arange(10) dim_a = 2 ...
Axel Donath's user avatar
  • 1,831

15 30 50 per page
1
2 3 4 5
1333