Skip to main content

All Questions

Tagged with
2 votes
2 answers
61 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
0 votes
1 answer
58 views

nums[:] = unique anyone please explain this line of code [duplicate]

class Solution(object): def removeDuplicates(self, nums): unique = [] for num in nums: if num not in unique: unique.append(num) nums[:] ...
Siva Anchuri's user avatar
4 votes
1 answer
227 views

Optimizing LeetCode's "Minimum Pair Removal to Sort Array II" Solution to Prevent Time Limit Exceeded Errors

I am working on the LeetCode problem 3510. Minimum Pair Removal to Sort Array II: Given an array nums, perform the following operation any number of times: Select the adjacent pair with the minimum ...
manhera's user avatar
  • 49
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
-4 votes
0 answers
61 views

Save images to disk from array in python [duplicate]

I would like to also save the images in the array, I'm able to return them but not save them, I get AttributeError: 'Axes' object has no attribute 'array_interface' import random import matplotlib....
daffer's user avatar
  • 21
-5 votes
1 answer
53 views

Fastest and cleaner ways to insert, update, delete 2-dimensional array [duplicate]

I'm newbie in python language and have some prolem here. I have a list of name and score for example: score = [['Andy', 80], ['John', 70], ['Diana', 100]] I want to Delete or Update score based on it'...
Tommy Sayugo'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
0 votes
1 answer
21 views

elasticsearch query with Python lists returns "Can't get text on a START_ARRAY at 1:30"

I'm new with elastic (any also with python) but have some first success: es = Elasticsearch(['http://localhost:9200'], basic_auth=('user', 'pw')) query_body = { "query": { "...
Andre Bergmann's user avatar
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
22 views

Issue with Input Array on Random Forest Model with Both Numerical and Categorical Features

I am obtaining a ValueError regarding the input arrays and there dimension. I am trying to create a Random Forest Regression Model for price prediction using both numerical features and categorical ...
leakie's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
2302