# Questions tagged [numpy]

NumPy is one of the fundamental packages used for scientific computing in the Python ecosystem. Specifically, NumPy is used for numerical computing and uses n-dimensional arrays.

361 questions
Filter by
Sorted by
Tagged with
1 vote
98 views

### Why can't I specify the correct NumPy size? [closed]

In the network (model of Keras, Sequential), the input layer must have 4 neurons. The input must be 1 list, the length of which is 4, each element is a number. ...
7k views

### Count the max number of consecutive 1 and 0 in Pandas Dataframe [closed]

Hey I have the following Dataset import pandas as pd df = pd.DataFrame({ 'column1': [0,0,1,0,1,0,0,1,1,0,1,1,1]}) I want to be able to count the number of ...
6k views

...
8k views

### Is it valid to use numpy.gradient to find slope of line as well as slope of curve at any point?

what is the difference between slope of the line and slope of the curve? Is it valid to use numpy.gradient to find the slope of the line and slope of the curve at ...
• 1,481
14k views

### How to find slope of curve at certain points

how to find slope at certain points circled in blue in below curve ? Are these below 2 approaches valid ? though they give different results . How to automatically find the points where the slope ...
• 1,481
875 views

### How can I count the number of matching zero elements between two numpy arrays?

I have a function that returns the predicted accuracy of a time-series model. I have two equally-sized numpy arrays, one for the actual direction and one for the predicted direction. I'm classifying ...
• 135
160 views

### Expectation Maximization Algorithm (EM) for Gaussian Mixture Models (GMMs)

I'm trying to apply the Expectation Maximization algorithm (EM) to a Gaussian Mixture Model (GMM) using Python and NumPy. The PDF document I am basing my implementation on can be found here. Below are ...
• 133
37 views

### How can I reshape this array?

I have few difficulties in picking values from an array. Here is a simplified version of the concerned part of the code. (If you would like to put the whole code please mention it) ...
72 views

### Transform large pd.Series into a DataFrame of n columns

I have a pd.Series with, for instance, n lines. I would like to transform this series in a ...
• 395
73 views

### What is the use of the np.ndarray() function and how is it used?

I just started Data Science and I want to know what the np.ndarray() function's use is, and in which scenario(s) it is used.
3k views

### How do I view my K features with SelectKBest? [closed]

I am getting an error for "no attribute columns". Because of this, I can't see the selected K features and can't build plots: First occurrence of error: Second occurrence of error: I'm also ...
1 vote
48 views

### pandas memory issues

What are some good "best practices" for dealing with large datasets in pandas and numpy? Typically i read data from csv files and use numpy and pandas to prepare them for machine learning and AI ...
• 1,959
2k views

### Iterative Reweighted Least Squares in python

I am trying to manually implement the irls logistic regression (Chapter 4.3.3 in Bishop - Pattern Recognition And Machine Learning) in python. For updating the weights, I am using \$w' = w-(\Phi^TR\...
433 views

### find monthly climatology for a particular month

I have a 10-year sst monthly data. I want to plot the interannual monthly climatology for the month of October. By using the code I have for python with me I am able to plot the interannual monthly ...
2k views

### value error of incompatible wrong dimension during training a model

I was implementing a decision tree on a dataset. Before that, I wanted to transform a particular column with CountVectorizer. For this, I am using pipeline to make it simpler. But there is an error of ...
• 165
829 views

### How to find the average over an area of center for a given radius

I have an excel file which contains the lat and long values of the center of a Tropical Cyclone(TC). The excel file is as given below: ...
1 vote
8k views

### Set value of a column based on values of other columns (Pandas)

The last time I used Python is some time ago so some things have faded away. I have a given dataset, with multiple columns. I want to create a new column and set the values based on multiple values (...
116 views

### Implementing single variable Linear Regression in python

I'm trying to implement LMS algorithm in python. I have the following code: ...
• 101
2k views

### Trying to understand the result provided by np.linalg.norm function in numpy (normalisation)

I'm new to data science with a moderate math background. I'm playing around with numpy and can across the following: So after reading np.linalg.norm, to my ...
• 103
489 views

### How to run list comprehensions on GPU?

Is there a way to run complex list comprehensions like the following on GPU? ...
1 vote
21 views

### Fit model function out defined data range

I have asked this on SO but it has not been well accepted because it seems to be more about data science than programming. Let's say I have a set of data ...
• 111
3k views

### Matplotlib Bar graph -ValueError: shape mismatch:(x,y)

While plotting the bar graph for number of attempt on x-aixs and time-taken on y-axis as per below code, getting Value error.Trace of error is included below. ...
96 views

### Why is my LSTM, stateful network getting 0 accuracy

I'm building a NN to predict stock prices but I'm getting an accuracy of 0, I really don't know what hyper parameters to play with anymore but it seems to always get this accuracy Build LSTM model <...
625 views

### Numpy ndarray holding string with unknown data type

I ran the following code in a jupyter notebook cell ndarrs=np.array(["1.2","1.5","1.6"], dtype=np.string_) print(ndarrs.dtype) It returned ...
1 vote
454 views

### Reshaping Numpy arrays

I am having a problem trying to reshape my numpy array. i have a 2 dimensional array and i want to make it a 3D array. I have looked everywhere but even if i find some answering my question they just ...
1 vote
58 views

### Parallelization of a MIMO linear filter

I would like to implement a Multi Input Multi Output filtering operation, acting as fast as possible on batches of data. Here is my current implementation: ...
• 11
1 vote
499 views

### fastai - using 'untar_data' function in kaggle kernel

I have recently started with fastai lesson 1 and I am using kaggle to run the course notebooks. While going through the ‘lesson1-pets’ notebook we use ...
• 161
1 vote
420 views

### How to find average lag time with variance & confidence of two time series

I have two variables as time series, one a consequent of the other, I would like to find the average time delay it takes the dependent variable to act on the independent variable. Additionally, I ...
1 vote
1k views

### How to code a simple forward propagation of recurrent neural networks?

I know the theory behind recurrent neural networks or RNN but I am confused about its implementation. This is an rnn equation I got from the web, I tried to code the forward propagation alone in ...
• 301
1 vote
44 views

### Why does averaging over vector values cause errors?

As a way to improve my model, I want to average GloVe vectors over a sentence. However, I can't get np.mean to work. The following code works when not averaging over words. (copied from other code) <...
• 135
248 views

### Getting the leave-one-out error on least square regression to fit polynomials

I need to implement least square regression to fit polynomials of degree 1-27. I then need to get the leave-one-out error (kfold cross validation where k = n). After doing a lot of research it seems ...
165 views

### Error in numpy array assignment

I'm trying to upload 17 images into a 4d numpy array, each image size is (256,256,1), so basically I'm using the 0th dimension for collection of different images. Following is my code: ...
69 views

361 views

### Neural network does not work on XOR

So, I am trying to implement a neural network in Python by only using NumPy. I have tried to do this by following 3Blue1Brown's video's about the topic, however, when testing my implementation, the ...
• 11
1k views

### Assign a unique cluster based on a dataframe column with KMeans Algorithm [closed]

I have the following df ...
• 123
1 vote
145 views

### Stratified K fold same index present in both test and valid set

I am trying to do a stratified k fold cross validation for my dataset and want to keep an isolated 10% test set from the dataset and use the remaining for training and validation. Below is the code ...
• 23
1 vote
303 views

### Random Parameters to fix in ML to perform controlled experiments

Many algorithms and methods in modern Machine Learning techniques contain randomness, and because of that, running the same ML script several times can result in different outputs, therefore accuracy ...
234 views

### tensorflow pseudo inverse doesn't work for complex matrices!

The Tensorflow documentation here says that: tf.linalg.pinv is ''analogous to numpy.linalg.pinv. It differs only in default value of rcond''. However, tf.linalg.pinv requires the matrix to ...
• 33
2k views

### How to apply a groupby rolling function to create multiple columns in the dataframe

I am setting up a volume profile series over a stock data. I have implemented the market profile code from this github repo and the link to the data is here and the example here. Some Sample of data ...
• 171
6k views

### Combine 100 2D arrays into one 3D array

I have 100 2D lists a0 to a99, it is easy to convert them into arrays (I verified already): ...
• 291
2k views

### Ways to simulate weather data over several periods (Python or R)?

I have a time series dataset that has several variables for a state/province for fixed periods of time. That is for state A, there are samples from April 2017 to July 2019. Of course, I thought adding ...
• 265
1 vote
284 views

### Implementing "full convolution" to find gradient w.r.t the convolution layer inputs

I've been trying to implement "full convolution" w.r.t to convolution layer inputs. According to this article, it looks like this: So, I wrote this function: ...
• 125
4k views

### Convert Numpy array with 'n' and 'y' into integer array of 0 and 1

I have a NumPy array of strings: 'n', 'y', wanna convert it into integer array of 0, 1, how to convert it? ...
• 81
75 views

### Machine learning dataframe dimension concept vs NumPy dimension

From Machine Learning for Absolute Beginners: A Plain English Introduction: Contained in each column is a feature. A feature is also known as variable, a dimension or an attribute - but they all ...
• 157
1k views

### NumPy -- ImportError: PyInit__multiarray_umath [closed]

I'm facing the below error while importing NumPy library. I have tried all of the suggestions advised by Python in its error log, but no luck. Strangely, when I use Python's OS library and print the "...
• 451
1 vote
230 views

### Pandas dataframe with multiple observations per model

I currently have a pandas dataframe with the following format ...
1k views

### Trouble in calculating the covariance matrix

I'm trying to calculate the covariance matrix for a dummy dataset using the following formula, but it's not matching with the actual result. Let's say the dummy dataset contains three features, #...
• 165
1 vote
41 views

### How to do Back Propagation Updation for below code?

Below is the code by Siraj Raval for implementing Neural Networks from Scratch. I have some doubts regarding the Code: Why during updation he did W2 = W2 + L1.T.dot(L2_Delta). I Mean shouldn't it be ...
• 31
77 views

### How should I improve my Vectorized Gradient descent linear regression model?

I wrote a vectorized Gradient descent implementation of the linear regression model. The Dataset looks something like: It's Not Working properly as I am getting negative R Squared error I don't ...
• 31