Ad
Result Of Function Linspace
Could you explain me this result please? I expected value as [0, 0.1, 0.4, 0.9, ...]
.
>>> np.linspace(0, 1, 10) ** 2
array([0. , 0.01234568, 0.04938272, 0.11111111, 0.19753086,
0.30864198, 0.44444444, 0.60493827, 0.79012346, 1. ])
Ad
Answer
np.linspace(0, 1, 10)
gives ten values including both endpoints:
>>> np.linspace(0, 1, 10)
array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,
0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ])
When you square these values, you get the numbers you see. This is referred to as a "fence-post problem"; 10 posts give you only 9 panels:
1 2 3 4 5 6 7 8 9 10
|-|-|-|-|-|-|-|-|-|
1 2 3 4 5 6 7 8 9
so each step is actually 1/9, not 1/10. I think you wanted:
>>> np.linspace(0, 1, 11) ** 2
array([0. , 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1. ])
Alternatively, if you don't want 1.
at the end, you can explicitly exclude the endpoint per the docs:
>>> np.linspace(0, 1, 10, endpoint=False) ** 2
array([0. , 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81])
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad