« first day (3962 days earlier)      last day (1209 days later) » 

01:06
@SAJW Yes, that's ok. But you shouldn't use sum as an identifier because it's the name of a built-in function, which sums lists & other iterators. Eg, sum(range(5)). Note that you don't need to supply a start arg for range when the range starts at zero.
cbg guys
As a matter of style, we usually put a space either side of operators. Here's the PEP-008 style guide, which has become the semi-official style guide for the Python community. You don't have to obey PEP-8, but it makes it easier for others to read your code if you do (mostly) follow its recommendations.
@SAJW Your pi series is the famous Leibniz series, which is one of the slowest ways known to compute pi. You need to do a million iterations just to get 6 decimal places. Fortunately, it's easy to make a much faster pi calculator.
cbg, @python_user
The Leibniz series basically calculates $\pi/4 = \arctan(1)$, using the Taylor series expansion: $\arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + \ldots$. If we use that series with smaller x, the convergence is much faster.
It's easy to show that arctan(1) = arctan(1/2) + arctan(1/3). Here's a visual proof:
So we just need to compute those two arctans and sum them. There are faster series than the Taylor series, but it's fast enough for computing pi to the limit of precision of Python floats (~1.0E-15)
01:30
do you work at a physics related area or is physics your hobby?
Here's a version, running on the SageMathCell server. Pi calculator. But try to code it yourself before looking at my code.
@python_user No, physics & astronomy are just hobbies.
got it, just curious that was it
No worries
sage is basically python?
Here's a pi program, using a mysterious algorithm by Dutch mathematician / computer scientist, Dik T. Winter. It's not very fast, but it only uses integer arithmetic.
@python_user Basically. It's a computer algebra system built on top of Python, so the core syntax is identical, apart from a couple of things. The main syntactic difference is that you can use ^ for exponentiation, and you have to use ^^ if you want the xor operator.
01:43
why remove ** for exponentiation? does it have a different meaning in sage?
ohh, "can use", got it, just tried ** and it does work
@python_user It's not removed, you can still use **, if you want. The preprocessor just does a simple regex string replace to convert ^ to **. Ssge is built for mathematicians, and mathematicians use ^ all the time in LaTeX / MathJax.
Sage tries to keep its calculations symbolic, as much as possible. Which is great when you need it, but it can be annoying when you don't, until you get used to it.
Eg, try print(sin(pi/6))
gives me 1/2, my math skills are rusty to understand if that is good or bad
It also handles fractions automatically. It has its own Integer type, but you can use int() to convert it to a plain Python int.
but it is kinda handy to not import math for pi and sin
python gives me 0.49999999999999994 ok now I see
A better example is print(sin(pi/7)), which it can't simplify.
01:52
thats funny, but if I use this result at a different place it gets applied accordingly?
Yes. So when you do a chain or loop of calculations with expressions like that, you can end up with a huge expression.
would assume that would make debugging need more work than normal, for someone like me who has to print the intermediate values to know if I am on the right track
If you need its numeric value, you can use the n function or method, to get the value with as much precision as you want. Eg, pi.n(prec=150) will give you pi, with 150 bits of precision (compared to 53 bits of normal floats).
just one more step than the usual print, debugging is almost the same then
I was doing a simple program yesterday that was doing square roots in a loop, and plotting the results. It worked ok for small loops, but got really slow for larger loops, and it took me a few minutes to realise what the problem was.
01:57
which was?
I just needed to use n() inside the loop. Without it, Sage was chugging along symbolically computing expressions with hundreds of nested square roots, like sqrt(a1 + sqrt(a2 + sqrt(a3 + ...
it was calculating with higher precision all the time without that? which would make it slower?
Not higher precision. It was creating a symbolic object consisting of hundreds of nested terms, and calculating algebraically with it.
got it
Sage has no idea of the numeric value of such expressions, until you call the n function. But it knows the rules of algebra for manipulating stuff like (a+b)*(c+d), the rules for multiplying square roots, etc.
02:06
ok that explains it a bit more, this is where it differs much from python then
One cute thing that Sage has is symbolic variables. You can do stuff like x = var('x') and a, b = var('a,b') which creates symbolic variables with those names. And you can use those variables to do algebra & calculus
So if you then do print((a + b)^2) you get a^2 + 2*a*b + b^2
I get (a + b)^2 still
not the expanded form
@python_user Oops. Sorry. Do this: ((a+b)^2).simplify_full()
yeah that works now, does it do this for most algebraic stuff?
I remember memorizing this as "formula" when I was in school laurel
You can also do f = (a + b)^2 to bind the expression to a name. And that name is callable, eg f(a=3, b=4)
You can also do f(a=3)
02:16
creates a partial?
Yes!
knowing python and how sage works (since the last 15 mins)I would normally expect that behavior then
And you can pass these things as args to a normal Python function. Eg with def func(u): return u*u + 1 If you call func(x) it returns x^2 + 1
@python_user Yep. It's pretty logical.
ok this is really useful for those who need this
I personally dont have a need for sage or any math library, but I would see my science / math friends benefiting from this
so this is a simpler / easy to use version of sympy? I have not used sympy but I am making a wild guess
SymPy is included in Sage. See stackoverflow.com/q/17847902/4014959
02:28
of course, some had to have asked it :D
Most of the time when I'm using SageMathCell, I'm doing plain Python, and not using any Sage features, except maybe its plotting facilities, which are mostly from matplotlib.
Of course, it's not really plain Python, because I'm using Sage integers & floats, but most of the time, that makes no difference.
if you do math I guess this difference would be pretty obvious soon, but for someone like me, it wouldnt really matter
that answer kinda differentiates it well
It can be annoying when you try to pass an integer to some stdlib function and it complains that it needs an int, not an Integer.
I can see that being a problem, though I would assume some sage equivalent or modified stdlib that can handle these existed
Most of the time, it's not an issue. The Sage Integer supplies its numeric value. But sometime the Python lib function tries to operate on the whole object. Eg, you can't pass a Sage Integer to random.seed
That's because random.seed used to accept any hashable object, but that's been restricted in recent versions.
02:39
you dont have to import anything in sage?
or its just math symbols like sin cos pi are in the namespace? plot functions are also in the namespace by default?
02:56
@python_user Sorry, I was getting a coffee.
You do have to import stdlib stuff, and some sage stuff, but it pre-imports a ton of stuff for you.
Try len(dir()) It returns 1902. So there's a lot of stuff sitting in that global namespace.
no not all, I had to leave as well, I hate saturday work shifts :(
yeah just tried, there is a lot indeed
03:20
Sage uses Numpy for bulk number crunching, so there's usually no problem calling Numpy in Sage and passing stuff back & forth between them. Eg, You can do m = matrix(a) to convert a Numpy array to a Sage matrix, or a = np.array(m), to do the reverse process.
I am going though sage source code to see how it looks like
hey @U12-Forward
Hi
Long time I haven't been in this room
I dont think much has changed, I have only been for around a year though
03:31
For more details about SageMath, take a look at sagemath.org/tour.html That page also has a link to A Guided Tour
Cabbage, @U12-Forward
Oh yeah! Almost forgot salad language
Cabbage @PM2Ring
I am kinda curious why is the list.index stop parameter set to 9223372036854775807?
I will ask a question later when more people are online
On SO
I am new here!!
wasuuuuuuuuuuuuuuuup
I made a calculator app, Wanna check it out??
I guess it doesn't really matter at the moment because the room isn't busy, but I try to not flood the room with Sage stuff. It's kind of on topic, but not of general interest.
I made it with python
yeah
@PM2Ring yeah, I learnt something new, so thanks for that :D
03:37
@U12-Forward That's 2**63 - 1, which is the largest positive 64 bit integer.
@python_user My pleasure!
@Duffy you can link your github python repo or pastebin if its just a single python file, users who have time would give you reviews
@PM2Ring Oh cool, will post on SO still, you could answer :)
@U12-Forward I don't think that would be a good question for SO. And it'd probably be a dupe on Computer Science.
@PM2Ring That's true
Yeah I just found one
Excellent
03:41
Not exactly the same but similar cs.stackexchange.com/questions/101597/…
Oh yeah!
@python_user That's more concrete
but I guess one has to know that 9223372036854775807 is the max limit (as mentioned by PM), to arrive at this question, to me at first glance that is just a random number
There's no need for the index to go that high. A machine with that much RAM would be huge. ;) But it's comvenient to use a machine integer for array indices. And in Python, it needs to be a signed integer, because we permit negative indices.
@python_user Me too
@PM2Ring Haha exactly
On my computer x = list(range(100000000)) can barely even run...
On my computer the limit is:
>>> x = list(range(10000000000))
Traceback (most recent call last):
  File "<pyshell#102>", line 1, in <module>
    x = list(range(10000000000))
MemoryError
>>>
it's my new computer, still got some extra RAM not added in yet
03:48
it instantly throws the error (in my laptop)? I would have expected it to at least wait for a while then throw that
@python_user I tried with x = list(range(1000000000))
And it almost crashed my PC lol
x = list(range(10000000000))
with one more 0 it instantly return the error
maybe my 4gb is too old for this
@python_user Yeah
Don't forget that a Python integer is an object, not a simple machine integer. So on 64 bit Python, a small integer object (i.e., one that fits in 64 bits) occupies 28 bytes.
You can get sizes of objects using sys.getsizeof
@PM2Ring Yeap!
03:58
Also, at the low level, a list isn't an array of objects. It's an array of pointers to objects. So when you do range(1000, 2000), you need 56 bytes for the list object itself, 1000*8 bytes for the pointers, and 1000*28 bytes for the integers from 1000 to 2000
OTOH, for list(range(100)), Python doesn't need to create the integer objects, since small integer objects from -5 to 256 are built into the interpreter.
@PM2Ring Yeah, the one that gives the MemoryError is the conversion to list, just doing range any number would work, because it only creates a reference object
Right.
@PM2Ring Exactly! here is an example:
>>> id(200)
140716424380432
>>> id(200)
140716424380432
>>> id(1000)
1442912301264
>>> id(1000)
1442912301328
>>>
for numbers under 256, writing them always refer to the same object
If you do need to work with a huge sequence, you're better off using a Numpy array, which doesn't have all those overheads. And it's much faster to initialise a big array than to grow a big list.
but for over 256, writing them creates a new object each time
@PM2Ring Yes exactly
I usually have projects where I work with and
Well sometimes got some completely different work to do, i.e. using and or
Ugh so few questions...
 
2 hours later…
06:14
Rhubarb guys!
rbrb
 
2 hours later…
08:15
Anyone online?
actually nvm
08:52
Cbg
09:08
happy weekend cbg
Happy weekend, anything planned?
09:33
I'll possibly visit some relatives over the weekend, fingers crossed!
09:54
That's nice
10:51
@PM2Ring so did I understand it: arctan(1/2) + arctan(1/3) is faster to approximate than arctan(1)? and could I improve it further if I find out what arctan(1/2), arctan(1/3) are in terms of smaller x?
11:31
Note that you can also test this yourself @SAJW using timeit
12:29
@SAJW Yes! So this leads to a whole infinite family of pi algorithms. By a nice "coincidence", arctan(1/2) = arctan(1/3) + arctan(1/7). So you can combine that with the previous equation to get arctan(1) = 2*arctan(1/3) + arctan(1/7)
Now tan(theta) = 1 / cot(theta), so arctan(1/n) = arccot(n). It's traditional to use numbers of this form because then we're just summing pure reciprocal in the Taylor series. That comes in useful when you're trying to calculate large numbers of digits... especially in the days before computers. ;) A few people gained a permanent place in maths history by doing these calculations to hundreds of digits.
@SAJW This stuff is probably not that interesting to the general room population, so we should probably continue this conversation in the Math room.
12:52
Hi everyone
I am in the process of making my matplotlib issue reproducibible
I have a plot like this:
as you can see, the labels of the y axis are completely ridiculous
any idea why this happens?
(Yeah I know I haven't provided much detail, working on it...)
@PM2Ring It's not like we're not used to see this kind of conversation here :P
@zabop Well, it's either matplotlib that adds the decimals, or you did. We can't answer it for the yticks are a mess until you post the code. Why not wait until you had the example ready?
I thought it might be some well known issue.
I am struggling to make the issue reproducible.
Fair. I haven't used matplotlib for several years tbh.
No worries :)
12:59
Have you specified/enforced yticks?
No
The key might be that
I am plotting the values of a pandas column
and that column has strs in it
and maybe the conversion is screwed up, looking into that... (ie I'm trying to reproduce this with random data)
Tbh I don't think the plot makes any sense anyway. If I look at the y values, you're trying to represent data on a linear axis that isn't linear?
I think I've made it reproducible
If I do:
np.random.seed(42)
x=np.arange(0,50)
y=np.random.normal(loc=3000,scale=1,size=50)
Then:
plt.scatter(x,y)
I get a plot, but if I do:
df=pd.DataFrame.from_dict({'x':x,'y':y.astype(str)})
plt.scatter(df.x,df.y)
@roganjosh Are they sorted as strings?
Nevermind
Don't ask me
13:05
and these gave different answers
@AlexandreMarcq yeah, in the real use case, yes
@roganjosh You are probably right, the sent plot seems wrong.
Ok I think I'm gonna post a question on the main site
See you those of you who are interested :) (Thanks @roganjosh for your attention.)
Hmm. Well maybe you'll get some answers but really I'm struggling to understand what you're plotting from the get-go. @AlexandreMarcq #NotMyGraph
@roganjosh I hope the post makes it clear (it is titled "What is being plotted when I pass on a str column of a Pandas dataframe to matplotlib?", asked like a minute ago.)
Something about the plotted data looks sensible as it cascade from left-to-right, but I can't fathom it. Before I look at your question, I question what you're trying to display with the wonky y axis
@roganjosh I feel like this or #NotMyMCVE could come handy in this room
@roganjosh In real life: some data retrieved through an API, in the reproducible example I just generated a bunch of random numbers.
13:23
I'm so lost. Your question doesn't seem to approximate the question you've posted on main. I would have expected things to blow up if you were comparing strings to ints, but... Yeah, I don't know where to start
You're using Python 3 for a start?
cbg. it's simple, isn't it? y is literally being treated like strings because you..well..you did pass it as strings
(disclaimer, havent seen whatever question you asked on main)
now... the fact that this is also a post on main means we shouldn't even be discussing it here
which makes me grumble. starts grumbling
I think you're right anyway. I guess the question is genuine in "what am I seeing?" but I don't have a robust answer about the lexicographical ordering. What you're seeing is nonsense...
what, no. it's not nonsense
it's verbatim whatever goes in comes out
It's nonsense in terms of what you wanted to plot
yes.
or i suppose, to phrase it differently, garbage in, garbage out
13:33
true. I'll backtrack on my statement
fwiw the question has an accepted answer now
 
2 hours later…
15:20
@AlexandreMarcq True. :) But I wanted to use a fair bit of MathJax in my explanation, and we don't usually use that in this room. Here's the link if you're curious: chat.stackexchange.com/transcript/message/58947315#58947315 Chat doesn't have builtin MathJax support, but there's a link in the Math room info section to a page with several bookmarklets that enable MathJax.
16:00
I want to append to a csv file, but if the file doesn't yet exist (or is empty), then I want to write a header row. How terrible of an idea is it to use if file.tell() == 0: instead of something like if path.stat().st_size == 0:?
16:12
i can't think of an issue under normal use
17:08
@PM2Ring Thanks, I'll have a look
 
1 hour later…
18:13
hello!
using pyinstaller module the executable pops up a terminal window
how to get rid of it?
Have you tried passing --noconsole?
how do I make f"{var : n}" returns decimal like 3.0 e.g 9 / 3 = 3.0
I try right now
@Aran-Fey That works perfectly!
thanks mate!
@RoyalFrog How many decimals? f'{var:.1f} maybe?
18:29
okay, so, previously, you've helped me out with checking for float and int (thank you for that), but on this version, it has a loop to iterate over every number and I decided to use the f-string integer type suggested to me by Kevin. But that function converts the result into int for division in particular.
Link: https://dpaste.com/63SXVZCWD

I tried it in doctest, it returns a testing failure where it expected 3.0 or .0 value in division.
but if that doesn't work, may I know how do I do the same using this similar function because is_integer won't work on list...
def check_int_float(number: float) -> float:

    if number.is_integer(): number = int(number)

    return number
This doesn't really help me understand your goal. There is no doctest in the code you posted, and you've done nothing to clarify how the number should be formatted
ohh, sorry, I think it's better if I just post the full code. I tried to only replicate the issue with lesser code.
I'm trying to make the program returns division with decimal but the f-string will convert it to integer instead. For example, when user enters 6 and 3 and chooses to do a division on the numbers, it should return 2.0 and not 2
18:45
And if the input is 1.5 * 3.8? Then it should be printed as an int because that's not a division?
Anyway, it sounds like you want to use different format specifiers depending on some condition. Python actually allows placeholders inside the format specifier, so you can do stuff like this:
if user_choice == 4:
    fmt = ''
else:
    fmt = 'n'

print(f'{result:{fmt}}')
It should be printed as it is, 5.69... It's only the division in particular
19:03
oh it works...
How many number would you like to calculate?: 2

Numbers: 9

Numbers: 3

Select an option | 1 | 2 | 3 |: 3

Result: 3.0
by the way, which section of the string operations can I read about this specifier, the one with the semicolon
19:18
Actually, I found it, and again, thank you so much.
 
4 hours later…
23:10
Good day everyone. I came across this [issues.apache.org/jira/browse/ARROW-12225](issue) where I would need to compile the pyarrow package on my own system. I followed the instructions [arrow.apache.org/docs/developers/… to compile pyarrow.
All completed without issue. I then installed the compiled package into a separate venv using my Pipfile. I did the following: pyarrow = { path = '/tmp/repos/arrow/python' } and I now see the package installed in my venv directory. However the same issue persists, and I'm stuck now on what my options are. Any advice on how to proceed?

« first day (3962 days earlier)      last day (1209 days later) »