This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Calculation influenced by print
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, mark.dickinson, paul.moore, steve.dower, steven.daprano, tim.golden, wby78826, zach.ware
Priority: normal Keywords:

Created on 2021-12-30 02:23 by wby78826, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
supertrend.py wby78826, 2021-12-30 02:23 python script
Messages (4)
msg409343 - (view) Author: wby78826 (wby78826) Date: 2021-12-30 02:23
(Could be a numpy bug)
##Just run the script, then uncomment Line 14 and run again
The result of "supertrend" is different, depending on whether I print "LB" first or not.
If I don't print it first, the result is wrong.

It also does'nt matter if I print it to stdout or stderr, it only works this way.

(sry if I did something wrong)
msg409350 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-12-30 07:00
This is likely not a bug in python. You might have better luck asking on a numpy support list.

That said, what results do you get, and what do you expect to get? We don't know what error you're seeing.

You might replace:
print("LB: ", LB)

with:
str(LB)

and see what happens. That's the only operation that's called on LB when you're printing.
msg409355 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-12-30 09:43
Please try to provide a minimal reproducible example:

https://stackoverflow.com/help/minimal-reproducible-example

http://sscce.org/

At the very least, you need to provide three pieces of information:

1. What you tried.
2. What you expected to happen (and why, if it isn't obvious).
3. What actually happened instead.


Ideally you should be able to get your example down to using one or two values, not three lists with 30 values each (90 values).
msg409433 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-12-31 20:34
When you do:

    FINUB = np.empty(len(close))
    FINLB = np.empty(len(close))

you're creating two *uninitialised* arrays of values. (See the NumPy documentation at https://numpy.org/doc/stable/reference/generated/numpy.empty.html.)

When you then do 

    FINUB[i] = UB[i] if UB[i] < FINUB[i-1] \
            	and close[i-1] > FINUB[i] else FINUB[i-1]

on the first iteration of the loop (i = 1), you make use of the (undefined) value in FINUB[0] to compute FINUB[1].

In other words, this is a bug in your code, rather than in Python or NumPy.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90357
2021-12-31 20:34:19mark.dickinsonsetstatus: open -> closed

nosy: + mark.dickinson
messages: + msg409433

resolution: not a bug
stage: resolved
2021-12-30 09:43:14steven.dapranosetnosy: + steven.daprano
messages: + msg409355
2021-12-30 07:00:14eric.smithsetnosy: + eric.smith
messages: + msg409350
2021-12-30 02:23:22wby78826create