Questions tagged [numpy]
NumPy is one of the many modules in Python that adds support of large multidimensional arrays and matrixes, along with a large library of high-level mathematical functions for operations with these arrays.
numpy
27,100
questions with no upvoted or accepted answers
14
votes
0
answers
738
views
Pickle still fails for numpy.void objects
Over a year ago I reported a bug I encountered while pickling some fairly complex data. At the time I didn't know what the issue was and believed it might have had something todo with recursive ...
13
votes
2
answers
6k
views
Scipy optimize raises ValueError despite x0 being within bounds
I'm trying to fit a sigmoid curve onto a small set of points, basically generating a probability curve from a set of observations. I'm using scipy.optimize.curve_fit, with a slightly modified logistic ...
10
votes
0
answers
989
views
Numpy replace values and return new array
Is there a function in numpy similar to np.put that returns a new array instead of modifying an array in place? Something like this:
def put_copy(arr, ind, v, mode="raise"):
arr_copy = arr.copy()
...
10
votes
0
answers
2k
views
Problems with OpenGL 4 VBOs and Numpy arrays, Pyglet/Python
I'm getting started with using OpenGL 4 in Python (through Pyglet and some framework code I got off the net/wrote myself for loading Shaders/Programs), but I think I understand things fairly well, so ...
9
votes
2
answers
1k
views
Tensorflow DNNclassifier: error wile training (numpy.ndarray has no attribute index)
I am trying to train a DNNClassifier in tensorflow
Here is my code
train_input_fn = tf.estimator.inputs.pandas_input_fn(
x=X_train,
y=y_train,
batch_size=1000,
shuffle = True
)
...
9
votes
2
answers
4k
views
Convert a list of numpy arrays to json for return from flask api
I have a dictinary in python like this:
mydic = {
'x1': list_of_numpy_array,
'x2': a numpy_array,
'x3': a list_of_numpy_array,
'x4': a list_of_numpy_array
}
I want to send this ...
9
votes
1
answer
1k
views
Python loop taking more time at each iteration
I made a for loop which strangely increases in duration at each iteration although the amount of variables manipulated remains constant. The code is below with:
X [N*F]: a numpy array with N samples ...
9
votes
0
answers
2k
views
Do numpy or scipy implement sub-cubic multiplication
I've searched quite a bit, but I've only found homegrown reimplementations of Strassen matrix multiplication.
Wikipedia says that numpy uses BLAS (which includes a high-performance implementations ...
9
votes
1
answer
4k
views
How can I merge two pandas DataFrames based on a function instead of just where values are equal?
I have two DataFrames that each have a column for firstname. I'd like to merge the columns on those strings, but on the Levenshtein distance as opposed to just where the strings are equal.
I'm ...
9
votes
1
answer
13k
views
python pickle size limit
i want to pickle a large (1810392*255) numpy array. However when pickling i get an error:
[...]error: 'i' format requires -2147483648 <= number <= 2147483647
Code:
import numpy
import pickle
...
8
votes
1
answer
3k
views
How to type hint function to be compatible with numpy
Source code of example.py:
from typing import Union, Any
import numpy as np
Number = Union[int, float, np.floating[Any]]
def add_one(num: Number) -> Number:
return num + 1
inputs = [1, 2, 3]
...
8
votes
0
answers
641
views
something wrong about scipy and numpy, when i import scipy.stats.linregress
When I import scipy.stats.linregress, to do something about ols, there is a TypeError.
When I run my code in PyCharm, all is OK. There is no error and I can get the right results.
But when I debug my ...
8
votes
1
answer
700
views
numpy with mypy: indexing NDArray returns Any type
Is it possible to index numpy arrays are receive at least the same type?
Running the following code through mypy reveals the following types:
import numpy as np
from numpy.typing import NDArray
a = ...
8
votes
0
answers
3k
views
Failed to install Numpy 1.20.2 with Poetry on Python 3.9
When I try to install Numpy 1.20.2 module with Python Poetry 1.1.4 package manager (poetry add numpy) in a Python 3.9.0 virtual environment, I get:
ERROR: Failed building wheel for numpy
Failed to ...
8
votes
1
answer
303
views
Estimating maximum numpy array size to fit in memory
I have the following piece of code to estimate whether a new numpy array will fit in memory:
import numpy as np
from subprocess import Popen, PIPE
def getTotalMemory():
output, _= Popen(r'wmic ...