Category "numpy"

Using numpy.where function with multiple conditions but getting valueError

So I have a dataframe with multiple columns with numbers in them. It looks like this: H C T P R 300 200 500 0.3 500 400 300 0.2 I'm trying to perform operat

np.max() error: TypeError: only integer scalar arrays can be converted to a scalar index

I'm trying to get the np.max() function to work like a relu() function but keep getting this error: >>>np.max(0, np.arange(-5, 5)) -------------------

Working with a multiindex dataframe, to get summation results over a boolean column, based on a condition from another column

We have a multiindex dataframe that looks like: date condition_1 condition_2 item1 0 2021-06-10 06:30:00+00:00

What is the syntax for writing txt file with multiple numpy arrays+scalars and how to read it in again?

I have 2 numpy arrays of same length lets call them A and B and 2 scalar values named C and D. I want to store these values into a single txt file. I thought of

Convert numpy array into Ray dataset

What is the correct way to convert numpy array into ray's dataset? I tried the following, but its not working. import numpy as np arr = np.array([[1.9, 1.0, 1.1

How to detect the colors nicely using OpenCV python

(It is not the whole code, it's just the main part) It's just a simple project I wanted to do, not school or anything. I want to segment out the red parts nicel

N-dimensional array indexing with numpy

I have imported a cube in Python and I would like to index the cube but in 'k' axis (N and M are two integer numbers), and then cross it by a plane (b) in the

Why does numpy.angle(0+0j) answer pi instead of zero

I am creating an array of complex numbers and compute the angle. When I set the magnitude to zero, I expect the angle to always be zero. However, I get pi if th

combine two rows with negligible threshold on a groupby dataframe

I have a raw dataframe(simplified) as below: ColumnA startime endtime A 2022-02-23 08:22:32.113000+00:00 2022-02-23 10:54:04.163000+00:00 A 2022-02-23 10:54:04

how to repeat a numpy vector to create an array with the rest of array being zeros

I would like the create the following numpy array, based on the following vector e = numpy.array([1,0,0,0,0,0]) a = [ [e, 0, ---, 0], [0, e, ---, 0],

Removing values from an 2d array

I have a 2 dimensional numpy array and want to remove all 'false' values. A nested array with different lengths should be created. [['false' 'value1' 'false' 'f

python random_sample to generate values

I am currently using random_sample to generate weightage allocation for 3 stocks where each row values add up to 1 and I rounded them to 2dp. weightage=[] n = 0

Within a pandas DF, how can I snag last two parts of a list as a single string for conditional output?

I'm doing some modification to a CSV via pandas. For one of the situations, I want to use parse a URL into a list, grab the last two items of that list, and out

TypeError: 'float' object cannot be interpreted as an integer on linspace

TypeError Traceback (most recent call last) d:\website\SpeechProcessForMachineLearning-master\SpeechProcessForMachineLearning

Python - stitch images back together after slicing

I have a directory of image patches that are all the same size (33x33), the images are ordered so that the first 7 images are row 1, then the next 7 images are

Every object's attribute update when I just want one

When making objects of a certain class, I give them a matrix as an attribute and store these objects in a different class, however when I change this matrix for

How to convert a array of string to array of float using

I have a array as shown below, in that I am having a variable called f, I need to assign the some value for this variable f say 2 and convert this into a floati

How to fix the NumPy .dtype 'NoneType' error

I am running the following Python code in PyCharm debug mode. import numpy as np, pandas as pd, numpy.polynomial.chebyshev as chebyshev from pathlib import Path

How do I turn a file into a RAW bitstring?

How do I read a file and turn it to a RAW bit string? For example I open an image that is 512kb, It reads the file byte by byte, and it spits out the long bit s

4 I am trying to put array into a pandas dataframe

import pandas as pd import numpy as np zeros=np.zeros((6,6)) arra=np.array([zeros]) rownames=['A','B','C','D','E','F'] colnames=[['one','tow','three','four','f