Array of size 'n' with common difference < 1
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
I know that there is another easy method...... Please give me a replay ........ Thanking you.............. -- DILEEPKUMAR. R J R F, IIT DELHI
Use " >> np.arange(-60, 90.0001, 0.25)" Youngung Jeong Graduate student Materials Mechanics Laboratory Graduate Institute of Ferrous Technology Pohang University of Science and Technology On Fri, Apr 29, 2011 at 4:26 PM, dileep kunjaai <dileepkunjaai@gmail.com>wrote:
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
I know that there is another easy method...... Please give me a replay ........ Thanking you..............
-- DILEEPKUMAR. R J R F, IIT DELHI
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Friday 29 April 2011 12:56 PM, dileep kunjaai wrote:
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
I know that there is another easy method...... Please give me a replay ........
Thanking you..............
-- DILEEPKUMAR. R J R F, IIT DELHI
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
use the numpy.ogrid command: lat =numpy.mgrid[-60:90:.25] pratik
On Friday 29 April 2011 01:01 PM, pratik wrote:
On Friday 29 April 2011 12:56 PM, dileep kunjaai wrote:
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
I know that there is another easy method...... Please give me a replay ........
Thanking you..............
-- DILEEPKUMAR. R J R F, IIT DELHI
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
use the numpy.ogrid command: lat =numpy.mgrid[-60:90:.25]
pratik i meant numpy.mgrid (not ogrid) :)
pratik
On 4/29/11 12:31 AM, pratik wrote:
On Friday 29 April 2011 12:56 PM, dileep kunjaai wrote:
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
xrange() (or range(), or np.arange()) is almost never the right solution for floating point ranges, due to the intricacies of floating point precision.
lat =numpy.mgrid[-60:90:.25]
or np.linspace: np.linspace(-60,90,((60.+90.)*4. + 1)) ((60.+90.)*4. + 1) is the number of points you want -- the +1 because you want both end points. mgrid is usually used for 2-d (or higher) grids, though it looks like it makes sense for this use, too, though note that it doesn't give you both endpoints in this case. From the docs: """If the step length is not a complex number, then the stop is not inclusive. """ and an example: In [15]: np.mgrid[-1:3:.25] Out[15]: array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 , 2.75]) I think this is too bad, actually, because we're back to range()-type tricks to get the end point: In [20]: np.mgrid[-1:3.25:.25] Out[20]: array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 , 2.75, 3. ]) -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
Thank you sir: thank you....very much for ur time and consideration.................. On Fri, Apr 29, 2011 at 9:11 PM, Christopher Barker <Chris.Barker@noaa.gov>wrote:
On 4/29/11 12:31 AM, pratik wrote:
On Friday 29 April 2011 12:56 PM, dileep kunjaai wrote:
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
xrange() (or range(), or np.arange()) is almost never the right solution for floating point ranges, due to the intricacies of floating point precision.
lat =numpy.mgrid[-60:90:.25]
or np.linspace:
np.linspace(-60,90,((60.+90.)*4. + 1))
((60.+90.)*4. + 1) is the number of points you want -- the +1 because you want both end points.
mgrid is usually used for 2-d (or higher) grids, though it looks like it makes sense for this use, too, though note that it doesn't give you both endpoints in this case. From the docs:
"""If the step length is not a complex number, then the stop is not inclusive. """
and an example:
In [15]: np.mgrid[-1:3:.25] Out[15]: array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 , 2.75])
I think this is too bad, actually, because we're back to range()-type tricks to get the end point:
In [20]: np.mgrid[-1:3.25:.25] Out[20]: array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 , 2.75, 3. ])
-Chris
-- Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
-- DILEEPKUMAR. R J R F, IIT DELHI
On Fri, Apr 29, 2011 at 5:41 PM, Christopher Barker <Chris.Barker@noaa.gov> wrote:
On 4/29/11 12:31 AM, pratik wrote:
On Friday 29 April 2011 12:56 PM, dileep kunjaai wrote:
Dear sir, I am trying to make an array of varies from -60 to 90 with difference 0.25. I tried the following command ...
import numpy as N lat=N.array(xrange(-6000, 9000, 25), dtype=float) print lat/100
xrange() (or range(), or np.arange()) is almost never the right solution for floating point ranges, due to the intricacies of floating point precision.
lat =numpy.mgrid[-60:90:.25]
or np.linspace:
np.linspace(-60,90,((60.+90.)*4. + 1))
((60.+90.)*4. + 1) is the number of points you want -- the +1 because you want both end points.
mgrid is usually used for 2-d (or higher) grids, though it looks like it makes sense for this use, too, though note that it doesn't give you both endpoints in this case. From the docs:
"""If the step length is not a complex number, then the stop is not inclusive. """
and an example:
In [15]: np.mgrid[-1:3:.25] Out[15]: array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 , 2.75])
I think this is too bad, actually, because we're back to range()-type tricks to get the end point:
In [20]: np.mgrid[-1:3.25:.25] Out[20]: array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 , 2.75, 3. ])
Just for completeness, note this paragraph from the mgrid docs: However, if the step length is a *complex number* (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value *is inclusive*. -Sebastian Haase
On 4/29/11 1:27 PM, Sebastian Haase wrote:
Just for completeness, note this paragraph from the mgrid docs:
However, if the step length is a *complex number* (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value *is inclusive*.
OK -- for a kluge, I figure you could do complex, then take the real part, but I can't seem to get a complex grid to work at all: In [37]: np.mgrid[(0+0j):(1+0j):(0.1+0j)] Out[37]: array([], dtype=complex128) What am I doing wrong? Go it -- the docs could use some clarification here -- Actually, passing in a complex nubmer is a FLAG, indicating that the index means somethign different, but it's still doing everything with real numbers (floats). Wow, klunky API! but here is what the OP would want: np.mgrid[-60:90:((60.j+90.j)*4. + 1j)] which is klunkier that linspace. I'd have used two different function names for the different mgrid functionality, rather that than the complex kludge -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (5)
-
Christopher Barker
-
dileep kunjaai
-
pratik
-
Sebastian Haase
-
Youngung Jeong