Bitwise, the Python operators that you probably don't use...

preview_player
Показать описание
Sponsored by .TECH Domain - Here’s your chance to get your very own .TECH Domain and help children get their start in computer science!

Bitwise, the python operator that you probably don't use.

Here is some information on bitwise operators in python:

3 Data Science Learning Platforms I would recommend

I have created 2 Python Courses you might like

(These contain affiliate links, which means I receive a percentage of any sales made. There is no additional cost for anybody clicking on them)

👌 SUBSCRIBE to ME!👌
Рекомендации по теме
Комментарии
Автор

use these operators if you want to confuse your colleagues and look smart haha

wootwoot
Автор

def is_odd_fct(n):
return n & 1


def is_even_fct(n):
return 1 - (n & 1)


Or compute a variable (let say is_even_var), for a given n:
is_even_var = 1 - is_odd_fct(n)

alioudiouf
Автор

I use it quite often, for masking.

# df is a pandas DataFrame
filtered_df = df[ (df[a_col>3) & (df[another_col] == "some_string") ]

More rarely:
# arr is a numpy array
a_mask = (arr>1) & (arr<15)

wholebrain
Автор

Your videos motivate me each day to gain some more syntax, try some more problems(though I don't know much as you to solve them all).

dhruv_
Автор

where is link to learn more about bitwise operators ?,
good video btw

azmatkhan
Автор

dude, you're channel is absolutely sensational! please keep it

PedroAnacletoOficial
Автор

Do you have any advice on what I can learn while driving in the car? I want to get better at programming and data science. So any education in either of those fields is good with me. My commute is about 1.5 hours driving.

edu
Автор

Do you have any recommendations for good feature engineering books?

coleblender
Автор

It probably could be done like this:
return {0:b}.format(n).endswith(0)

DonaldFranciszekTusk
Автор

to check for speed you could show a for next loop to test all numbers from 1 to 100, 000, 000 and see the difference :)

riccardoronco
Автор

def test_for_odd(n): # a smaller format
return bool(n & 1)

blackraven
Автор

can you do similar videos on other bitwise operators, giving examples of how to use them. I never knew you could use & to determine whether number is odd or even for example, seems like a logical thing now that I think about it, but bits are so weird I never connected them to real life thing. it also seems like it would be knowledge applicable onto quantum computing, where basically all programming boils down to applying gates to qubits, which is like, applying bitwise operators to bits

cannot put into words how proud of my self I was when I figured out you could use hadamard gate to make a coin toss game ><

mimosveta
Автор

Could you instead do:
def is_even_ 2(n):
>> return not n & 1
???

frecio
Автор

How about return True or False rather than 1 or 0
def is_even(n):
return not ( n & 1)

jaadow
Автор

Wowhhh that bass is insan 😍 anyone noticed?

gurpreetchahal
Автор

# go fully bitwise

IsEven = lambda n: ~n & 1

def is_even(n):
return ~n & 1

PaulSmith-zsje
Автор

def is_even(n):
return not n & 1

benverret
Автор

Shouldn't the first function be:
def is_even(n):
if n % 2 == 0:
return 0
return 1

lucasrodrigues