Closed soulne4ny closed 8 years ago
Hi,
I was quite surprised with y = bool(z.real) and y = bool(z.imag) at https://github.com/jrjohansson/scientific-python-lectures/blame/master/Lecture-1-Introduction-to-Python-Programming.ipynb#L994
y = bool(z.real)
y = bool(z.imag)
While it would be ok for integers and it works as shown, it is useless as exact zero is quite uncommon as a result of a computation.
As well, complex to boolean conversion works quite well as it well fits into a scheme x != 0.
x != 0
>>> bool(1j) True >>> bool(1+0j) True >>> bool(0j) False
I've found bool(x) useful with x of type float when x is was previously converted from bool to float to keep all data unified and these values are not results of numerical computations.
bool(x)
x
float
bool
Hi,
I was quite surprised with
y = bool(z.real)
andy = bool(z.imag)
at https://github.com/jrjohansson/scientific-python-lectures/blame/master/Lecture-1-Introduction-to-Python-Programming.ipynb#L994While it would be ok for integers and it works as shown, it is useless as exact zero is quite uncommon as a result of a computation.
As well, complex to boolean conversion works quite well as it well fits into a scheme
x != 0
.