0

Can anyone help with best practices for avoiding this type of problem?

in: np.arrange(1, 2.2, .2) out: array([1. , 1.2, 1.4, 1.6, 1.8, 2. , 2.2])

Must have something to do with binary/base10 difficulties, as

in: np.arrange(1, 2.2, .2)[6] out: 2.1999999999999997

python version: 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]

numpy version: : 1.16.3

Mohsen Alyafei
  • 4,765
  • 3
  • 30
  • 42
Rylan
  • 1
  • Does this answer your question? [Inconsistent behavior in np.arange?](https://stackoverflow.com/questions/62217178/inconsistent-behavior-in-np-arange) – Ehsan Jul 15 '20 at 00:15

1 Answers1

0

Okay, answered my own question (rly just wanted to post on stackoverflow).

It's best to use numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0), and just set num to (start - stop)/spacing (+1 if endpoint=True).

Rylan
  • 1