All Samples(4284) | Call(4040) | Derive(0) | Import(244)
Convert the input to an array.
Parameters
----------
a : array_like
Input data, in any form that can be converted to an array. This
includes lists, lists of tuples, tuples, tuples of tuples, tuples
of lists and ndarrays.
dtype : data-type, optional
By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
Whether to use row-major ('C') or column-major ('F' for FORTRAN)
memory representation. Defaults to 'C'.
Returns
-------
out : ndarray
Array interpretation of `a`. No copy is performed if the input
is already an ndarray. If `a` is a subclass of ndarray, a base
class ndarray is returned.
See Also
--------
asanyarray : Similar function which passes through subclasses.
ascontiguousarray : Convert input to a contiguous array.
asfarray : Convert input to a floating point ndarray.
asfortranarray : Convert input to an ndarray with column-major
memory order.
asarray_chkfinite : Similar function which checks input for NaNs and Infs.
fromiter : Create an array from an iterator.
fromfunction : Construct an array by executing a function on grid
positions.
Examples
--------
Convert a list into an array:
>>> a = [1, 2]
>>> np.asarray(a)
array([1, 2])
Existing arrays are not copied:
>>> a = np.array([1, 2])
>>> np.asarray(a) is a
True
If `dtype` is set, array is copied only if dtype does not match:
>>> a = np.array([1, 2], dtype=np.float32)
>>> np.asarray(a, dtype=np.float32) is a
True
>>> np.asarray(a, dtype=np.float64) is a
False
Contrary to `asanyarray`, ndarray subclasses are not passed through:
>>> issubclass(np.matrix, np.ndarray)
True
>>> a = np.matrix([[1, 2]])
>>> np.asarray(a) is a
False
>>> np.asanyarray(a) is a
True
def asarray(a, dtype=None, order=None):
"""
Convert the input to an array.
Parameters
----------
a : array_like
Input data, in any form that can be converted to an array. This
includes lists, lists of tuples, tuples, tuples of tuples, tuples
of lists and ndarrays.
dtype : data-type, optional
By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
Whether to use row-major ('C') or column-major ('F' for FORTRAN)
memory representation. Defaults to 'C'.
Returns
-------
out : ndarray
Array interpretation of `a`. No copy is performed if the input
is already an ndarray. If `a` is a subclass of ndarray, a base
class ndarray is returned.
See Also
--------
asanyarray : Similar function which passes through subclasses.
ascontiguousarray : Convert input to a contiguous array.
asfarray : Convert input to a floating point ndarray.
asfortranarray : Convert input to an ndarray with column-major
memory order.
asarray_chkfinite : Similar function which checks input for NaNs and Infs.
fromiter : Create an array from an iterator.
fromfunction : Construct an array by executing a function on grid
positions.
Examples
--------
Convert a list into an array:
>>> a = [1, 2]
>>> np.asarray(a)
array([1, 2])
Existing arrays are not copied:
>>> a = np.array([1, 2])
>>> np.asarray(a) is a
True
If `dtype` is set, array is copied only if dtype does not match:
>>> a = np.array([1, 2], dtype=np.float32)
>>> np.asarray(a, dtype=np.float32) is a
True
>>> np.asarray(a, dtype=np.float64) is a
False
Contrary to `asanyarray`, ndarray subclasses are not passed through:
>>> issubclass(np.matrix, np.ndarray)
True
>>> a = np.matrix([[1, 2]])
>>> np.asarray(a) is a
False
>>> np.asanyarray(a) is a
True
"""
return array(a, dtype, copy=False, order=order)
def test_resample_img2img():
fimg = load_image(funcfile)
aimg = load_image(anatfile)
resimg = resample_img2img(fimg, fimg)
yield assert_true, np.allclose(np.asarray(resimg), np.asarray(fimg))
yield assert_raises, ValueError, resample_img2img, fimg, aimg
[0,0,0,1.]])
ir = resample(i, g2, a, (100,80,90))
yield assert_array_almost_equal, np.transpose(np.asarray(ir), (0,2,1)), i
def test_resample2d():
pylab.gca().set_ylim([0,99])
pylab.gca().set_xlim([0,89])
pylab.figure(num=4)
pylab.plot(np.asarray(ir))
def test_2d_from_3d():
a = np.identity(4)
g2 = ArrayCoordMap.from_shape(g, shape)[10]
ir = resample(i, g2.coordmap, a, g2.shape)
yield assert_array_almost_equal, np.asarray(ir), np.asarray(i[10])
@parametric
((0,39.5), 80),
i.reference)
ir = resample(i, zsl, a, (90, 80))
yield assert_true(np.allclose(np.asarray(ir), np.asarray(i[53])))
ysl = slices.yslice(22, (0,49.5), (0,39.5), i.reference, (100,80))
ir = resample(i, ysl.coordmap, a, ysl.shape)
yield assert_true(np.allclose(np.asarray(ir), np.asarray(i[:,45])))
xsl = slices.xslice(15.5, (0,49.5), (0,44.5), i.reference, (100,90))
ir = resample(i, xsl.coordmap, a, xsl.shape)
yield assert_true(np.allclose(np.asarray(ir), np.asarray(i[:,:,32])))
src/n/i/NiPy-OLD-HEAD/nipy/algorithms/tests/test_resample.py NiPy-OLD(Download)
def test_resample_img2img():
fimg = load_image(funcfile)
aimg = load_image(anatfile)
resimg = resample_img2img(fimg, fimg)
yield assert_true, np.allclose(np.asarray(resimg), np.asarray(fimg))
yield assert_raises, ValueError, resample_img2img, fimg, aimg
[0,0,0,1.]])
ir = resample(i, g2, a, (100,80,90))
yield assert_array_almost_equal, np.transpose(np.asarray(ir), (0,2,1)), i
def test_resample2d():
pylab.gca().set_ylim([0,99])
pylab.gca().set_xlim([0,89])
pylab.figure(num=4)
pylab.plot(np.asarray(ir))
def test_2d_from_3d():
a = np.identity(4)
g2 = ArrayCoordMap.from_shape(g, shape)[10]
ir = resample(i, g2.coordmap, a, g2.shape)
yield assert_array_almost_equal, np.asarray(ir), np.asarray(i[10])
def test_slice_from_3d():
i.coordmap.output_coords,
(90,80))
ir = resample(i, zsl.coordmap, a, zsl.shape)
yield assert_true, np.allclose(np.asarray(ir), np.asarray(i[53]))
ysl = slices.yslice(22, (0,49.5), (0,39.5), i.coordmap.output_coords, (100,80))
ir = resample(i, ysl.coordmap, a, ysl.shape)
yield assert_true, np.allclose(np.asarray(ir), np.asarray(i[:,45]))
xsl = slices.xslice(15.5, (0,49.5), (0,44.5), i.coordmap.output_coords, (100,90))
ir = resample(i, xsl.coordmap, a, xsl.shape)
yield assert_true, np.allclose(np.asarray(ir), np.asarray(i[:,:,32]))
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/demo_agg_filter.py matplotlib(Download)
def smooth2d(A, sigma=3):
window_len = max(int(sigma), 3)*2+1
A1 = np.array([smooth1d(x, window_len) for x in np.asarray(A)])
A2 = np.transpose(A1)
A3 = np.array([smooth1d(x, window_len) for x in A2])
A4 = np.transpose(A3)
src/m/a/matplotlib-HEAD/examples/pylab_examples/demo_agg_filter.py matplotlib(Download)
def smooth2d(A, sigma=3):
window_len = max(int(sigma), 3)*2+1
A1 = np.array([smooth1d(x, window_len) for x in np.asarray(A)])
A2 = np.transpose(A1)
A3 = np.array([smooth1d(x, window_len) for x in A2])
A4 = np.transpose(A3)
src/n/i/nipy-HEAD/examples/neurospin/need_data/erp.py nipy(Download)
nsubjects = Y.shape[2] nconditions = Y.shape[3] ndata = nsubjects*nconditions conditions = np.asarray(range(nconditions))*50 + 50 saturation = np.array([0,0,1,1,1,1]) # Regressors baseline = np.ones(ndata) conditions = np.tile(conditions, nsubjects) saturation = np.tile(saturation, nsubjects) subject_factor = np.repeat(np.asarray(range(nsubjects)),6)
src/m/a/matplotlib-HEAD/matplotlib/examples/event_handling/poly_editor.py matplotlib(Download)
""" from matplotlib.artist import Artist from matplotlib.patches import Polygon, CirclePolygon from numpy import sqrt, nonzero, equal, array, asarray, dot, amin, cos, sin from matplotlib.mlab import dist_point_to_segment
def get_ind_under_point(self, event):
'get the index of the vertex under point if within epsilon tolerance'
# display coords
xy = asarray(self.poly.xy)
xyt = self.poly.get_transform().transform(xy)
xt, yt = xyt[:, 0], xyt[:, 1]
src/n/i/NiPy-OLD-HEAD/examples/neurospin/erp.py NiPy-OLD(Download)
nsubjects = Y.shape[2] nconditions = Y.shape[3] ndata = nsubjects*nconditions conditions = np.asarray(range(nconditions))*50 + 50 saturation = np.array([0,0,1,1,1,1]) # Regressors baseline = np.ones(ndata) conditions = np.tile(conditions, nsubjects) saturation = np.tile(saturation, nsubjects) subject_factor = np.repeat(np.asarray(range(nsubjects)),6)
src/m/a/matplotlib-HEAD/examples/event_handling/poly_editor.py matplotlib(Download)
""" from matplotlib.artist import Artist from matplotlib.patches import Polygon, CirclePolygon from numpy import sqrt, nonzero, equal, array, asarray, dot, amin, cos, sin from matplotlib.mlab import dist_point_to_segment
def get_ind_under_point(self, event):
'get the index of the vertex under point if within epsilon tolerance'
# display coords
xy = asarray(self.poly.xy)
xyt = self.poly.get_transform().transform(xy)
xt, yt = xyt[:, 0], xyt[:, 1]
src/p/y/PyMVPA-HEAD/doc/examples/pylab_2d.py PyMVPA(Download)
# if ridge, use the prediction, otherwise use the values
if c == 'Ridge Regression':
# use the prediction
res = np.asarray(pre)
elif 'Nearest-Ne' in c:
# Use the votes
res = clf.ca.estimates[:, 1] / np.sum(clf.ca.estimates, axis=1)
elif c == 'Logistic Regression':
# get out the values used for the prediction
res = np.asarray(clf.ca.estimates)
elif c in ['SMLR']:
res = np.asarray(clf.ca.estimates[:, 1])
# visualization of trade-off just plot relative
# "trade-off" which determines decision boundaries if an
# alternative log-odd value was chosen for a cutoff
res = np.asarray(clf.ca.estimates[:, 1]
- clf.ca.estimates[:, 0])
# Scale and position around 0.5
res = 0.5 + res/max(np.abs(res))
else:
# get the probabilities from the svm
res = np.asarray([(q[1][1] - q[1][0] + 1) / 2
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/ginput_manual_clabel.py matplotlib(Download)
pts = []
while len(pts) < 3:
tellme('Select 3 corners with mouse')
pts = np.asarray( plt.ginput(3,timeout=-1) )
if len(pts) < 3:
tellme('Too few points, starting over')
time.sleep(1) # Wait a second
happy = False
while not happy:
tellme( 'Select two corners of zoom, middle mouse button to finish' )
pts = np.asarray( plt.ginput(2,timeout=-1) )
happy = len(pts) < 2
if happy: break
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next