PEP 8: comparison to True should be if cond is True: or if cond:

2024/10/3 10:34:54

PyCharm is throwing a warning when I do np.where(temp == True)

My full code:

from numpy import where, arraya = array([[0.4682], [0.5318]])
b = array([[0.29828851, 0., 0.28676873, 0., 0., 0., 0., 0.28801431, 0., 0., 0.71283046, 0.],[0.70171149, 0., 0.71323127, 0., 0., 0., 0., 0.71198569, 0., 0., 0.28716954, 0.]])temp = b > 1.1*a
pos = where(temp == True)print(pos) 

The code does not work as expected if I change temp == True to temp is True as suggested in other post.

How should this warning be resolved?

where(temp) works. Thanks a lot !! @Joao Vitorino Thanks for the explanation, @jedwards. It helps.

Answer

Don't compare boolean against boolean.

You should check if is True or false.

b == true
if b: # If b is Truedo something 

In your case

temp = b > 1.1*a
pos = where(temp)  

Here some explanations

https://en.xdnf.cn/q/70743.html

Related Q&A

Getting the title of youtube video in pytube3?

I am trying to build an app to download YouTube videos in python using pytube3. But I am unable to retrieve the title of the video. Here goes my code: from pytube import YouTube yt = YouTube(link) prin…

pandas - concat with columns of same categories turns to object

I want to concatenate two dataframes with category-type columns, by first adding the missing categories to each column.df = pd.DataFrame({"a": pd.Categorical(["foo", "foo"…

Python convert Excel File (xls or xlsx) to/from ODS

Ive been scouring the net to find a Python library or tool that can converts an Excel file to/from ODS format, but havent been able to come across anything. I need the ability to input and output data …

Select pandas frame rows based on two columns values

I wish to select some specific rows based on two column values. For example:d = {user : [1., 2., 3., 4] ,item : [5., 6., 7., 8.],f1 : [9., 16., 17., 18.], f2:[4,5,6,5], f3:[4,5,5,8]} df = pd.DataFrame(…

Using scipy sparse matrices to solve system of equations

This is a follow up to How to set up and solve simultaneous equations in python but I feel deserves its own reputation points for any answer.For a fixed integer n, I have a set of 2(n-1) simultaneous e…

Segmentation Fault in Pandas read_csv

I have Python 2.7.5 on Os X 10.9 with Pandas version 0.12.0-943-gaef5061. When I download this train.csv file and run read_csv, I get Segmentation Fault 11. I have experimented with the file encoding…

Multiple subprocesses with timeouts

Im using a recipe that relies on SIGALRM to set alarm interrupt -- Using module subprocess with timeoutThe problem is that I have more than one Python script using signal.ALARM process to set time-outs…

what is the difference between tfidf vectorizer and tfidf transformer

I know that the formula for tfidf vectorizer is Count of word/Total count * log(Number of documents / no.of documents where word is present)I saw theres tfidf transformer in the scikit learn and I just…

Use Pandas string method contains on a Series containing lists of strings

Given a simple Pandas Series that contains some strings which can consist of more than one sentence:In: import pandas as pd s = pd.Series([This is a long text. It has multiple sentences.,Do you see? M…

Is this the correct way of whitening an image in python?

I am trying to zero-center and whiten CIFAR10 dataset, but the result I get looks like random noise! Cifar10 dataset contains 60,000 color images of size 32x32. The training set contains 50,000 and tes…