# All Questions

Tagged with python-3.x numpy

9,115
questions

-1votes

0answers

10views

### Ragged nested array need to be converted to array of float

I have a ragged nested array with class 'numpy.ndarray' which I want to convert it to a string of float which I already try to use np.asfarray to change it. the problem is that, my Jupyter Notebook ...

0votes

0answers

10views

### Ragged Nested Numpy Array to Tensor

I have ragged nested arrays of .npy file that I have processed. The error is that it my model failed to convert the NumPy array to a Tensor with the remark 'Unsupported object type list') I have try ...

-1votes

0answers

13views

### How numpy limits the number of CPU cores

My CPU is multi-core. I want numpy to execute on a single core or with a single thread. What should I do?
The configuration is as follows.
numpy.show_config()
blas_mkl_info:
NOT AVAILABLE
blis_info:
...

0votes

0answers

14views

### I was tring to generate sound waves, so I made a program, but it did not work

I was tring to generate sound waves, so I made a program, but it did not work, anyone has a solution to the problem?
my code:
import pygame as pg
import numpy as np
pg.init()
pg.mixer.init()
...

0votes

1answer

13views

### Python assigning attribute changing length

I have a class that accepts a parameter X. This parameter X is a numpy array, containing lists that contain ints.
array([[ 101, 2002, 8542, ..., 0, 0, 0],
[ 101, 2002, 8974, ..., ...

1vote

2answers

37views

### Change field in row if other row has same value in different field

I'm looking for a Python-based solution to a common task I often run into. (I know, there must be cool SQL-magic for this, but... not now.)
Given a table, we want to change the field f2 if oid is the ...

0votes

3answers

23views

### multi-dimensional dictionary to dataframe python

dict_abc = {'A': [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
'B': [[4, 4, 4], [2, 2, 3],],
'C': [[4, 6, 0]]
}
I would like to convert this to a dataframe in the form
| x | y | z |
...

1vote

3answers

51views

### Python Array Computations: get two values per item

I'm trying to get a list with all numbers that are in the form 6n+1 or 6n-1.
Currently I have this:
n = 100000000
l = int(n/6)
f1 = lambda x: (6*x)-1
f3 = lambda x: (6*x)+1
primeCandidate = [f(i) for ...

0votes

0answers

11views

### I am getting the error while running the python code for numpy.frombuffer a bytes-like object is required, not 'NoneType'

This code is running well in Windows (python version = 3.10.3) but when I run it in Linux (python version = 3.9.7) it is throwing the following error message:
import numpy as np
sound_buffer = np....

0votes

1answer

29views

### How to get the column name of a dataframe from values in a numpy array

I have a df with 15 columns:
df.columns:
0 class
1 name
2 location
3 income
4 edu_level
--
14 marital_status
after some transformations I got an numpy.ndarray with ...

-1votes

0answers

23views

### While writing the matrix in complex form it is showing the following error. But it is working properly while using two for loops

`steps =2.0
a = np.linspace(-3,3,steps)g = np.linspace(-3,3,steps)
gamma = 2
GG = np.vectorize(complex)
def Ham(i,k):H= np.zeros((2,2),dtype=complex)H[0,0] = i+1jgammaH[0,1] = kH[1,0] = kH[1,1] = ...

0votes

1answer

20views

### TypeError: 'tuple' object is not callable (for print statement)

import numpy as np
a=np.load('ampli/array.npy')
print(a)
Im trying to print an npy array like this from colab. I've used this exact syntax to print other arrays and it has worked but this isnt ...

1vote

2answers

19views

### How to do MinIFS in Python Dataframe

I have a dataframe that has 7 columns. I want to create an 8th column with the output of the equation. The equation is: from columns 2-7, for those numbers that are above Col 1, output the minimum ...

0votes

0answers

30views

### Debugging of VQE implementation on IBMQ

I was trying to implement VQE on IBMQ, but every time I run the cell, it has no return. I took a long time on it and right now need help on debugging.
I followed steps in Qiskit VQE implementation and ...

0votes

1answer

24views

### pandas mask indexing misshaped DataFrame

Is there a built in way with pandas to accomplish this.
I'd prefer to avoid pd.concat([...],1) .all(1) methods as the dataset I'm working with has missing data points.
main.py
import pandas as pd
...

0votes

0answers

10views

### How do I include the numpy includedir for a setuptools extension?

I have a setup.py that looks like this, minus the irrelevant bits.
import numpy
my_module = Extension(
'my_module',
......
include_dirs=[numpy.get_include()],
)
setup(
...
...

-3votes

0answers

31views

### Load the data using numpy [closed]

I am having an error which says - "axis 2 is out of bounds for array of dimension 1"
in the below code
data = np.rollaxis(np.load('data.npy'),2,5)
data[:,:,:,:,[0,1,2]] = data[:,:,:,:,[...

2votes

3answers

31views

### How to update existing columns in a dataframe based on multiple conditions on other columns in python?

df1:
Pan_no Target Debt_aum Hml
Xxx 0 5000 Low
YYY 1 0 medium
ZZZ 0 200 Low
Aaa 1 15000 High
Yyy 1 0 ...

3votes

2answers

51views

### how to create a new column in a dataframe based on conditions in another dataframe?

df1:
Variables left right
0 AUM -0.001 28.20
1 AUM 28.20 40.28
2 AUM 40.28 58.27
3 AUM 58.27 80.72
4 AUM 80.72 100....

0votes

1answer

63views

### How can I use for loop in my original code with multiple conditions in python?

I have a df like the below:
df:
Variable | Cutoff
0 abs | (-88.01,2.0]
1. abs | (2.0,6.0]
2. abs | (6.0, 18.0]
and so on..
I have another dataframe as X
X:
Pan_no | abs
...

-1votes

1answer

50views

### Pandas binning and sum using custom bins, on categorical columns

I want to change my source dataframe to output df output dataframe. Here i'm creating the load column based on min and max of the load column from the source dataframe and create equally spaced bins ...

0votes

0answers

30views

### How to create a new column in python based on multiple conditions in a for loop?

I have a dataframe as woe like the below
Variable | Cutoff
0 ABS_Returns | (-88.001, 2.0]
1 ABS_Returns | (2.0, 6.0]
2 ABS_Returns | (6.0, 18.0]
0 AUM | (-0.001, 10.0]
1 AUM ...

1vote

1answer

24views

### Arranging a list based on the distance of its elements from a given value

Let's assume we have a list like the following
[2.3, 1.02, 1.99, 0.99, 0.089, 0, 1.1, -1.1, -2.1]
We want to arrange the elements of this list based on their distance from target value equal to 1 in ...

0votes

0answers

35views

### Python - Numba produces syntax error for For-Loop

I have the following code in which I create two 1D NumPy arrays (f0src and f1src) and then create a two for loop for calculate some function with every combination of f0src and f1src arrays. I pre-...

1vote

1answer

38views

### How to convert rows into columns (as value but not header) in Python

In the following dataset, I need to convert each row for the “description” under “name" column (for example, inventory1, inventory2 and inventory3) into two separate columns (namely description1 ...

0votes

1answer

23views

### Create date ranges from an array of dates

Let's say I have below array of dates (not necessarily sorted):
import numpy as np
np.array(["2000Q1", "2000Q2", "2000Q3", "2000Q4", "2001Q1", "...

0votes

3answers

30views

### How to compare two columns and input the smaller one in a new column in pandas?

I am working on a DataFrame that looks like this. I'd like to choose the faster date of the two and put it into another column.
col1
col2
col3
2015-01-03
2015-01-04
2022-02-22
2017-01-02
and my ...

0votes

1answer

37views

### How I can resolve this problem of my code? [closed]

I get a lot of graphs when I compile the code below.
But I want everything to be graphed in a single figure. This is my code:
import numpy as np ...

1vote

3answers

63views

### How to compare current row with previous 2 rows based on certain conditions in Python

I have a dataset similar to below, I want to compare all rows for each inventory item based on the conditions that
if "value" column is not null, then flag it "yes"
Else if "...

2votes

3answers

29views

### Flagging NaN values based on a condition and year

I am trying to get this requirement of flagging NaN values based on condition and particular year, below is my code:
import pandas as pd
import numpy as np
s={'Fruits':['Apple','Orange', 'Banana', '...

1vote

2answers

27views

### Plotting Using Trapezodial Rule

So I am trying to plot f = cos(x) using the trapezoidal rule but I keep getting an error saying:
TypeError: only length-1 arrays can be converted to Python scalars
I am not sure how the function is ...

3votes

2answers

43views

### How to Accurate result on cv2.findcontours to find objects in BW/black-white image?

This is a perfect sample image that includes range of black objects.
And this code suppose to find every black plants
import cv2 as cv
import numpy as np
img = cv.imread("12.jpg")
tresh_min=...

0votes

1answer

32views

### Why it is showing Index error and Incomplete data scrape while doing python web scraping?

I am trying to scrape the web page "https://global.oup.com/academic/content/series/v/very-short-introductions-vsi/?type=listing&lang=en&cc=in" after I run the script, it gives the ...

-1votes

0answers

44views

### Question: How to automate the manipulation of my arrays?

I have the following problem which i am deeply stuck on...
I have created a 3D grid of a cubic structure called material with shape (2,4,4) (so 32 grains each) . As you can see this only contains 0's ...

0votes

1answer

47views

### How can I interpolate values from two lists (in Python)?

I am relatively new to coding in Python. I have mainly used MatLab in the past and am used to having vectors that can be referenced explicitly rather than appended lists. I have a script where I ...

0votes

0answers

24views

### How to make a multi-colored plot in matplotlib?

How can I generate a multi-colored time series line chart in matplotlib? Trying to plot the y values and assign colors based on the codes. The x-axis of the plot would be the dates.
import numpy as ...

0votes

1answer

25views

### Is there a way to make a class behave like a tuple in numpy array indexing?

I would like to create a kind of Pos mutable class that acts as a 2D point supporting arithmetic operations. But I would like this class to behave as a tuple when used in the specific case of numpy ...

0votes

3answers

43views

### Splitting the array in python on the based of position

I have a array in python as:
newarray=['Title',
'Salary USD',
'Equity %',
'Equity USD',
'Work location',
'Years of Experience',
'Years at Startup',
'Stage',
'Size',
'Staff electrical engineer'...

0votes

0answers

15views

### regarding suppressing the warning message

While running a python project, I got the following warning message,
numpy\core\fromnumeric.py:3417: FutureWarning: In a future version, DataFrame.mean(axis=None) will return a scalar mean over the ...

1vote

2answers

34views

### Creating dataframe with multi level column index from from four 2d numpy arrays

I have four 2d numpy arrays:
import numpy as np
import pandas as pd
x1 = np.array([[2, 4, 1],
[2, 2, 1],
[1, 3, 3],
[2, 2, 1],
[3, 3, 2]])
x2 = np.array([[1, 2, 2],
...

1vote

1answer

31views

### How do I reshape a NumPy multi dimensional array to another array with the same dimensions, but different shape?

I have a NumPy multi dimensional array of shape (1,76,76,255). I want to reshape it to another multidimensional array of shape (1,255,76,76). It’s still a 4D array, but I need to change the data ...

1vote

1answer

29views

### Strange comportement of list/array

I want to understand why the comportement of my array is like that:
import numpy as np
import math
n=10
P=np.array([[0]*n]*n)
P[2][2]=1 #It works as I want
for i in range(n):
for j in range(n):
...

0votes

0answers

31views

### How can I fix IndexError: invalid index to scalar variable

I am trying to convert cartesian to spherical coordinates and following is my code. I am getting the error IndexError: invalid index to scalar variable when it's trying to calculate ph = math.atan2(-...

0votes

1answer

47views

### Chi square test with different sample sizes in Python

I have two sets of data as shown below. Each data set have a different length
X_data1 and Y_data1 (black binned data) have a length of 40 whereas X_data2 and Y_data2 (red) have a length of 18k.
I ...

1vote

1answer

32views

### How can I calculate conditional counting for each entries of a tuple?

def Trigger(V1, P_T, N1, N2): # N1 = N_W # N2 = N_A
V = np.transpose(V1[:N1])
c = 0
for l in range(N2): # over number of antennas
if ( sum( (np.array(V[l]) >= ...

0votes

2answers

48views

### How to append N number of an array to the end of another array

I have an array of size 99 columns by 100 rows but want to add the last row of the 2D array to the end of the array N times. My current code to do this is:
import numpy
array = numpy .concatenate((l,...

1vote

0answers

19views

### Convert a datetime array in timestamp array

I have to convert a datetime array into a timestamp array in python. My code t = np.asarray([(dt.datetime(yy,mm,dd,hh).timestamp()) for yy,mm,dd,hh in zip(year,months,days,hours)]) doesn't work and I ...

0votes

0answers

40views

### Python: load data with multiple delimiter into multiple columns using column name from data

I have a text file with the below data. I want to create multiple files with this data.
Input File format:
"id","first_name|Andrew~last_name|Dowards~email|adowards@example.com~gender|...

0votes

0answers

18views

### Python - Contour plot with Numpy meshgrid

I have three arrays such as follows:
x = np.array([x1,x2,....x400])
y = np.array([y1,y2,....y400])
z = np.array([z1,z2,....z400])
The x and y values define a 2d plane with a length and depth of 400 ...

0votes

1answer

29views

### NaN appearance at seemingly random times when applying Butterworth filter to zero-centred signal

I have coded a band-pass Butterworth filter in Python 3.9.7 using scipy.signal.butter and scipy.signal.filtfilt and have been iterating through different critical frequency pairs for lower and upper ...