Questions tagged [numpy]
NumPy is a scientific and numerical computing extension to the Python programming language.
0
votes
0answers
8 views
Error in Numerical derivative
I am integrating a partial differential equation in which I have a fourth-order partial derivative in $x$ and the numerical integration in time is giving me absurd errors. The cause of the problem, I ...
0
votes
0answers
15 views
is the standard normalization same effect as numpy.log?
recently i'm learning data mining. from the website 'https://datahack.analyticsvidhya.com/contest/practice-problem-loan-prediction-iii/?utm_source=auto-email', the author uses sklearn ...
1
vote
1answer
24 views
how to subtract each element in a ndarray with each and every element of another ndarray in numpy
for example I have,
a =
[[0.4 0.87 0.24 0.1]
[0.6 0.93 0.34 0.98]
[0.5 0.32 0.09 0.99]
[0.4 0.11 0.18 0.65]
[0.5 0.98 0.47 0.78]]
b =
[[0.6 0.93 0.34 0.98]
[0.7 0.47 0.43 ...
2
votes
0answers
11 views
Multi-Core Numpy on ARM Cpu
I'm looking to do some work with NumPy on my Raspberry Pi 3 B+, which uses a ARM 4-core Cortex-A53 (ARMv8) 64-bit, and I'm not sure what the deal is with parallel optimization, blas, etc. Before ...
0
votes
1answer
19 views
Arrays manipulation and indexing
I am trying to plot a curve defined as follows :
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
limit1 = 50
nPoints1=50
x1 = np.arange(0,limit1,1)
noise = np.asarray(np....
0
votes
1answer
23 views
numpy array is immutable after matplotlib.pyplot.imread()
Why is the numpy array immutable after being read using matplotlib.pyplot.imread? What is the reasoning behind that?
>>> import matplotlib
>>> test=matplotlib.pyplot.imread('...
0
votes
0answers
15 views
FailedPreconditionError() while converting a tensor to a numpy array
I am trying to do a custom convolution operation by creating a custom layer in Keras.
However, I am getting a FailedPreconditionError()
This is the code I wrote for the call function is...
def call(...
0
votes
0answers
12 views
gradient descent cost convergence
I have a small script that has the cost converge to zero for data sets xa and ya, but no matter what values I use for 'iterations' and 'learning_rate', the best cost I can get to is 31.604 when using ...
0
votes
1answer
27 views
Filtering numpy array of numpy arrays
I've got a np array of array and I want to remove all elements that match a condition. I want to avoid for loops to try to make if faster.
My np array has size of N. And inside, there are arrays of ...
-1
votes
4answers
43 views
How to check if elements in one array exist in another array if so print the count using Python
I have two arrays
A=[1,2,3,4,6,5,5,5,8,9,7,7,7]
B=[1,5,7]
If elements of B in A then print the number of occurrences
output
1:1
5:3
7:3
1
vote
2answers
30 views
How do I calculate moving average with customized weight in pandas?
I have a dataframe than contains two columns, a: [1,2,3,4,5]; b: [1,0.4,0.3,0.5,0.2]. How can I make a column c such that:
c[0] = 1
c[i] = c[i-1]*b[i]+a[i]*(1-b[i])
so that c:[1,1.6,2.58,3.29,4....
-1
votes
2answers
10 views
Assertion error when making an MP4 video out of numpy arrays with OpenCV
I have this python code that should make a video:
import cv2
import numpy as np
out = cv2.VideoWriter("/tmp/test.mp4",
cv2.VideoWriter_fourcc(*'MP4V'),
25,...
1
vote
2answers
35 views
Numpy unique triangles in mesh
I have a mesh of triangles stored in numpy. Some triangles are duplicates and I want to remove them.
An example of my numpy array:
# Some points
a=(-2,-2,0)
b=(1,-2,0)
c=(1, 1,0)
d=(-2,1,0)
e=(-2,-2,...
12
votes
6answers
279 views
Find position of maximum per unique bin (binargmax)
Setup
Suppose I have
bins = np.array([0, 0, 1, 1, 2, 2, 2, 0, 1, 2])
vals = np.array([8, 7, 3, 4, 1, 2, 6, 5, 0, 9])
k = 3
I need the position of maximal values by unique bin in bins.
# Bin == 0
# ...
0
votes
1answer
20 views
pandas - fill in empty row values with other row values conditionally
I have a table that looks like this (the ratio column was merged from another table based on the codename and date):
date codename ratio
2018-01-01 A .5
2018-02-01 A
...
1
vote
1answer
26 views
Choose indices in numpy arrays on particular dimensions [duplicate]
It is hard to find a clear title but an example will put it clearly.
For example, my inputs are:
c = np.full((4, 3, 2), 5)
c[:,:,1] *= 2
ix = np.random.randint(0, 2, (4, 3))
if ix is:
array([[1, 0,...
0
votes
0answers
22 views
Numpy mask from cylinder coordinates
I generated the coordinates of a cylinder. Its two faces connect two arbitrary points already given.
Plot of cylinder
Is it possible to build a 3D numpy mask of the filled cylinder from the ...
0
votes
0answers
10 views
tslearn package not seeing numpy installation python
I'm trying to install python requirements in jenkins through
pip install requirements.cfg
For now i have 3 packages in requirements file: numpy, pandas and tslearn. Numpy and pandas are installed ...
0
votes
0answers
39 views
Calculate mean for lists
I want to calculate mean for lists of vectors. However received error message
ValueError Traceback (most recent call last)
<ipython-input-1293-04753fc36464> in ...
0
votes
1answer
47 views
TypeError: can't multiply sequence by non-int of type 'float' numpy
When I pass to numpy arrays of correct dimensions to the function below I get an error: TypeError: can't multiply sequence by non-int of type 'float'.
see picture
Please help.
def linear_forward(A, ...
0
votes
1answer
47 views
Python - Numpy issues with Pipeline
I have built a neural network and it works fine with a smaller dataset like 300,000 known good rows and 70,000 suspicious rows. I decided to increase the size of known good to 6.5 million rows but ...
0
votes
0answers
19 views
Numpy sort array by result of argsort [duplicate]
I want to sort an array and have both the indices and the values sorted.
It is quite a large array, so I don't want to do argsort and sort both.
How can I use the result of argsort to sort the array. ...
0
votes
0answers
18 views
Python (or prolog!) building an y array from a given set of sub-arrays, with items of the sub-arrays not part of y. Zebra like puzzle
I'd really need some help with a problem related to a mastermind-like game that I'm writing in my free time, to play with my nerd-friends :): I'm stuck with this, and it's quite challenging for me:
I ...
2
votes
1answer
23 views
Numpy - Apply a custom function on all combination of rows in matrix to get a new matrix?
I have the following function, that applies the histogram intersection kernel for 2 arrays:
def histogram_intersection_kernel(X, Y):
k = np.array([])
for x_i,y_i in zip(X,Y):
k = np.append(k,np....
-2
votes
0answers
28 views
Model predicts same output for all inputs
I'm training a neural network to perform object detection via a sliding window. I have already trained my network on 32x32 images with 10 classes of objects and got 92% accuracy on my validation set, ...
2
votes
1answer
15 views
Subsetting pandas df based on time ranges
I my df looks like this and is rather large:
contract time Open High Low Last
0 CME/TYH2018 2017-09-18 125.687500 125.750000 125.687500 125.750000
1 CME/...
1
vote
1answer
37 views
Add column with random number based on other column
I'm trying to add a column in a pandas dataframe which is a value on average equal to the initial column, but can deviate on each row some decimal points. Ideally deviating with a normal distribution, ...
-3
votes
1answer
47 views
How to randomly generate a fixed number of points for different space dimension in Numpy? [on hold]
I want to create an n-dimensional array with the constant number of random points and find the closest one to the origin in python.
To be exact I want to create uniformly distributed 100 random ...
0
votes
0answers
30 views
Plot vector field from contour lines
I have a set of data points (x,y,V), where V is the electric potential measured at the point (x,y). From this data, I have plotted several equipotential lines using matplotlib (Python), as shown:
...
1
vote
2answers
30 views
How do I solve this 'transpose' in Python?
I am trying to do some kind of reverse transpose where the ID(ISIN) becomes duplicates, but where the feature 'Period' defines the time period and the value-features goes from 3 features to the same ...
3
votes
2answers
72 views
Fast iteration over numpy array for squared residuals
I like to least-squares match data (a numpy array of floats) with many known signal shapes. My code works but is too slow for the many runs I plan to do:
import numpy
import time
samples = 50000
...
1
vote
1answer
26 views
How do I get a TIFF bytestream from an OpenCV image, rather than a numpy array?
In python, I want to convert an image that has been processed using OpenCV for transmission in a certain image format (TIFF in this case, but could be: BMP, JPEG, PNG, .....).
For this purpose it ...
0
votes
2answers
35 views
Converting string to numpy array and vice versa in python
I am having a numpy array which is the image read by open cv and pushing it to google big table as a string (since big table accepts basic data types). So I have converted the np array to string and ...
0
votes
1answer
17 views
How to append two numpy arrays if a for loop after loading data?
I have two numpy arrays. I want to append then along zero axis. If I use np.append command it demands two arguments. Whereas the following code loads first array and then second array. How I can ...
-1
votes
0answers
33 views
Identical size numpy arrays have vastly different size on disc
So, I've been toying around with numpy arrays for a project I am working on. I tried to compile two lists of identical sizes, which I then turned into numpy arrays using the numpy.asarray() method.
...
0
votes
2answers
63 views
How can this loop be vectorized?
I have a numpy array that looks like:
array([[ -1. , 184. , 0.5],
[ -1. , 174. , 1.0],
[ -1. , 104. , 0.5],
[ 1. , 44. , 0.5],
[ 1. , 28. , 0.5],
[ 1....
0
votes
2answers
38 views
Converting normal matrix to numpy
The purpose of this code is to arrange the lines, using the third collum as a parameter. If I use normal matrix, the program works just fine, but I need to use numpy, because it's part of a bigger ...
1
vote
5answers
46 views
Fast way to apply custom function to every pixel in image
I'm looking for a faster way to apply a custom function to an image which I use to remove a blue background. I have a function that calculates the distance each pixel is from approximately the blue ...
1
vote
1answer
25 views
Sliced numpy array does not modify original array
I've run into this interaction with arrays that I'm a little confused. I can work around it, but for my own understanding, I'd like to know what is going on.
Essentially, I have a datafile that I'm ...
0
votes
1answer
25 views
scipy.io has no attribute 'loadmat'
I am trying to use loadmat from scipy.io. According to their documentation [LINK], it should be fairly easy to use loadmat. This is how I use it:
import scipy.io as sio
mat_contents = sio.loadmat('...
-1
votes
0answers
28 views
Scikit-learn linear regression function error
I'm performing a regression function, I'm selecting weights by exhaustive optimization algorithms and for my first attempt I sell calculate possible values for 60 parameters (X's). I'm trying to ...
-1
votes
2answers
21 views
Restricting numpy.random.lognormal to a given range, Python
I'm trying to sample a random number using a log normal distribution fitted to a data set of ages.
Age_abscess = numpy.random.lognormal(mean=numpy.log(29.9090909),
sigma=numpy.log(11....
0
votes
1answer
25 views
find distance to reference items with numpy/pandas
I want to calculate the distances from a set of points to a set of reference points, where the number of references is different (and smaller) than the number of points. Think, for instance, the ...
0
votes
1answer
33 views
Image to np array, doing operations and back to image
Heay guys started with ML and trained my first classifier.
Used the Microsoft Dataset with dog/cat images.
What im trying is to go Image > array > operations back to an Imagefile.
I tried so many ...
1
vote
1answer
32 views
Function to create a non equally spaced array in numpy
I would like to create an array with the form [1, 2, 4, 8, 16, 32, ...]. Not always with that spacing between numbers.
Is there a linspace/arange type function which allows me to create vector of non ...
-2
votes
1answer
48 views
What´s the best solution to improve the speed of a python loop that iterates over a numpy array?
If anyone has time to take a look at this issue. What´s the best way to increase the processing speed of this function? It gets very slow if it has to deal with more than 50 000 values.Thank you.
...
-2
votes
1answer
22 views
Grouping equivalance row as 2D array in python for very large data set
I have 100k rows and I want to group it as explained below in python. A simple python iteration takes lots of time. How to optimize it using any python ML library?
[[1,2,3,4],[2,3],[1,2,3],[2,3],[...
1
vote
0answers
16 views
What is the difference between |U and U regarding numpy dtype specifier for strings [duplicate]
I know that
header = np.array(["AA","AC"],dtype='U2')
will create a numpy array containing strings that are made out of 2 letters.
How does it difer compared to
header = np.array(["AA","AC"],...
0
votes
1answer
38 views
numpy boolean indexing of a matrix
Please go easy on me as I'm still new to numpy and trying to wrap my head around some numpy concepts and I have this question:
The problem
I have a numpy array called boxes with boxes.shape = (2, ...
1
vote
2answers
24 views
Parsing multiple *.csv with ISO 8601 timestamp and custom tick
I am post-processing output data *.csv files and feel like using Python3.7/Numpy/Matplotlib.
Datas are minute-log-rotate-filenames:
POWER_2018-08-19T00:56.csv
POWER_2018-08-19T00:57.csv
POWER_2018-...