當前位置: 首頁>>代碼示例>>Python>>正文


Python array.from_array方法代碼示例

本文整理匯總了Python中dask.array.from_array方法的典型用法代碼示例。如果您正苦於以下問題:Python array.from_array方法的具體用法?Python array.from_array怎麽用?Python array.from_array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dask.array的用法示例。


在下文中一共展示了array.from_array方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ConstantArray

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def ConstantArray(value, size, chunks=100000):
    """
    Return a dask array of the specified ``size`` holding a single value.

    This uses numpy's "stride tricks" to avoid replicating
    the data in memory for each element of the array.

    Parameters
    ----------
    value : float
        the scalar value to fill the array with
    size : int
        the length of the returned dask array
    chunks : int, optional
        the size of the dask array chunks
    """
    ele = numpy.array(value)
    toret = numpy.lib.stride_tricks.as_strided(ele, [size] + list(ele.shape), [0] + list(ele.strides))
    return da.from_array(toret, chunks=chunks, name=False) 
開發者ID:bccp,項目名稱:nbodykit,代碼行數:21,代碼來源:transform.py

示例2: test_permutation

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_permutation(permutation_params):
    n_features, n_instances, n_permutations, mult = permutation_params
    xshape, yshape = (n_instances[0], n_features), (n_instances[1], n_features)
    np.random.seed(0)
    x = np.random.random(xshape).astype('float32')
    y = np.random.random(yshape).astype('float32') * mult
    xda = da.from_array(x, chunks=xshape)
    yda = da.from_array(y, chunks=yshape)

    kwargs = {'sigma': np.array([1.])}
    p_val = permutation_test(x, y, n_permutations=n_permutations,
                             metric=maximum_mean_discrepancy, **kwargs)
    p_val_da = permutation_test(xda, yda, n_permutations=n_permutations,
                                metric=maximum_mean_discrepancy, **kwargs)

    if mult == 1:
        assert p_val > .2 and p_val_da > .2
    elif mult > 1:
        assert p_val <= .2 and p_val_da <= .2 
開發者ID:SeldonIO,項目名稱:alibi-detect,代碼行數:21,代碼來源:test_statstest.py

示例3: test_gaussian_kernel

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_gaussian_kernel(gaussian_kernel_params):
    sigma, n_features, n_instances = gaussian_kernel_params
    xshape, yshape = (n_instances[0], n_features), (n_instances[1], n_features)
    x = np.random.random(xshape).astype('float32')
    y = np.random.random(yshape).astype('float32')
    xda = da.from_array(x, chunks=xshape)
    yda = da.from_array(y, chunks=yshape)

    gk_xy = gaussian_kernel(x, y, sigma=sigma)
    gk_xx = gaussian_kernel(x, x, sigma=sigma)

    gk_xy_da = gaussian_kernel(xda, yda, sigma=sigma).compute()
    gk_xx_da = gaussian_kernel(xda, xda, sigma=sigma).compute()

    assert gk_xy.shape == n_instances and gk_xx.shape == (xshape[0], xshape[0])
    assert (gk_xx == gk_xx_da).all() and (gk_xy == gk_xy_da).all()
    assert gk_xx.trace() == xshape[0] * len(sigma)
    assert (gk_xx > 0.).all() and (gk_xy > 0.).all() 
開發者ID:SeldonIO,項目名稱:alibi-detect,代碼行數:20,代碼來源:test_kernels.py

示例4: test_pairwise

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_pairwise(pairwise_params):
    n_features, n_instances = pairwise_params
    xshape, yshape = (n_instances[0], n_features), (n_instances[1], n_features)
    np.random.seed(0)
    x = np.random.random(xshape).astype('float32')
    y = np.random.random(yshape).astype('float32')
    xda = da.from_array(x, chunks=xshape)
    yda = da.from_array(y, chunks=yshape)

    dist_xx = pairwise_distance(x, x)
    dist_xy = pairwise_distance(x, y)
    dist_xx_da = pairwise_distance(xda, xda).compute()
    dist_xy_da = pairwise_distance(xda, yda).compute()

    assert dist_xx.shape == dist_xx_da.shape == (xshape[0], xshape[0])
    assert dist_xy.shape == dist_xy_da.shape == n_instances
    assert (dist_xx == dist_xx_da).all() and (dist_xy == dist_xy_da).all()
    assert dist_xx.trace() == 0. 
開發者ID:SeldonIO,項目名稱:alibi-detect,代碼行數:20,代碼來源:test_distance.py

示例5: test_mmd

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_mmd(mmd_params):
    n_features, n_instances = mmd_params
    xshape, yshape = (n_instances[0], n_features), (n_instances[1], n_features)
    np.random.seed(0)
    x = np.random.random(xshape).astype('float32')
    y = np.random.random(yshape).astype('float32')
    xda = da.from_array(x, chunks=xshape)
    yda = da.from_array(y, chunks=yshape)

    kwargs = {'sigma': np.array([1.])}
    mmd_xx = maximum_mean_discrepancy(x, x, **kwargs)
    mmd_xy = maximum_mean_discrepancy(x, y, **kwargs)
    mmd_xx_da = maximum_mean_discrepancy(xda, xda, **kwargs).compute()
    mmd_xy_da = maximum_mean_discrepancy(xda, yda, **kwargs).compute()

    assert mmd_xx == mmd_xx_da and mmd_xy == mmd_xy_da
    assert mmd_xy > mmd_xx 
開發者ID:SeldonIO,項目名稱:alibi-detect,代碼行數:19,代碼來源:test_distance.py

示例6: _get_hot_pixel_test_data_2d

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def _get_hot_pixel_test_data_2d():
    """Get artifical 2D dataset with hot pixels.

    Values are 50, except [21, 11] and [5, 38]
    being 50000 (to represent a "hot pixel").

    Examples
    --------
    >>> import pyxem.dummy_data.dask_test_data as dtd
    >>> data = dtd._get_hot_pixel_test_data_2d()

    """
    data = np.ones((40, 50)) * 50
    data[21, 11] = 50000
    data[5, 38] = 50000
    dask_array = da.from_array(data, chunks=(5, 5))
    return dask_array 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:19,代碼來源:dask_test_data.py

示例7: _get_hot_pixel_test_data_3d

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def _get_hot_pixel_test_data_3d():
    """Get artifical 3D dataset with hot pixels.

    Values are 50, except [2, 21, 11] and [1, 5, 38]
    being 50000 (to represent a "hot pixel").

    Examples
    --------
    >>> import pyxem.dummy_data.dask_test_data as dtd
    >>> data = dtd._get_hot_pixel_test_data_3d()

    """
    data = np.ones((5, 40, 50)) * 50
    data[2, 21, 11] = 50000
    data[1, 5, 38] = 50000
    dask_array = da.from_array(data, chunks=(5, 5, 5))
    return dask_array 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:19,代碼來源:dask_test_data.py

示例8: _get_hot_pixel_test_data_4d

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def _get_hot_pixel_test_data_4d():
    """Get artifical 4D dataset with hot pixels.

    Values are 50, except [4, 2, 21, 11] and [6, 1, 5, 38]
    being 50000 (to represent a "hot pixel").

    Examples
    --------
    >>> import pyxem.dummy_data.dask_test_data as dtd
    >>> data = dtd._get_hot_pixel_test_data_4d()

    """
    data = np.ones((10, 5, 40, 50)) * 50
    data[4, 2, 21, 11] = 50000
    data[6, 1, 5, 38] = 50000
    dask_array = da.from_array(data, chunks=(5, 5, 5, 5))
    return dask_array 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:19,代碼來源:dask_test_data.py

示例9: _get_dead_pixel_test_data_2d

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def _get_dead_pixel_test_data_2d():
    """Get artifical 2D dataset with dead pixels.

    Values are 50, except [14, 42] and [2, 12]
    being 0 (to represent a "dead pixel").

    Examples
    --------
    >>> import pyxem.dummy_data.dask_test_data as dtd
    >>> data = dtd._get_dead_pixel_test_data_2d()

    """
    data = np.ones((40, 50)) * 50
    data[14, 42] = 0
    data[2, 12] = 0
    dask_array = da.from_array(data, chunks=(5, 5))
    return dask_array 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:19,代碼來源:dask_test_data.py

示例10: _get_dead_pixel_test_data_3d

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def _get_dead_pixel_test_data_3d():
    """Get artifical 3D dataset with dead pixels.

    Values are 50, except [:, 14, 42] and [:, 2, 12]
    being 0 (to represent a "dead pixel").

    Examples
    --------
    >>> import pyxem.dummy_data.dask_test_data as dtd
    >>> data = dtd._get_dead_pixel_test_data_3d()

    """
    data = np.ones((5, 40, 50)) * 50
    data[:, 14, 42] = 0
    data[:, 2, 12] = 0
    dask_array = da.from_array(data, chunks=(5, 5, 5))
    return dask_array 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:19,代碼來源:dask_test_data.py

示例11: test_dask_array

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_dask_array(self):
        numpy_array = np.zeros((10, 10, 50, 50))
        numpy_array[:, :, 25, 25] = 1

        peak_array = np.zeros((numpy_array.shape[:-2]), dtype=np.object)
        real_array = np.zeros((numpy_array.shape[:-2]), dtype=np.object)
        for index in np.ndindex(numpy_array.shape[:-2]):
            islice = np.s_[index]
            peak_array[islice] = np.asarray([(27, 27)])
            real_array[islice] = np.asarray([(25, 25)])

        dask_array = da.from_array(numpy_array, chunks=(5, 5, 5, 5))
        dask_peak_array = da.from_array(peak_array, chunks=(5, 5))

        square_size = 12

        data = dt._peak_refinement_centre_of_mass(
            dask_array, dask_peak_array, square_size
        )
        data = data.compute()
        assert data.shape == (10, 10)
        assert np.sum(data - real_array).sum() == 0 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:24,代碼來源:test_dask_tools.py

示例12: test_array_different_dimensions

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_array_different_dimensions(self, nav_dims):
        shape = list(np.random.randint(2, 6, size=nav_dims))
        shape.extend([50, 50])
        chunks = [1] * nav_dims
        chunks.extend([25, 25])
        dask_array = da.random.random(size=shape, chunks=chunks)
        peak_array = np.zeros((dask_array.shape[:-2]), dtype=np.object)
        for index in np.ndindex(dask_array.shape[:-2]):
            islice = np.s_[index]
            peak_array[islice] = np.asarray([(27, 27)])
        square_size = 12
        peak_array_dask = da.from_array(peak_array, chunks=chunks[:-2])
        match_array_dask = dt._peak_refinement_centre_of_mass(
            dask_array, peak_array_dask, square_size
        )
        assert len(dask_array.shape) == nav_dims + 2
        match_array = match_array_dask.compute()
        assert peak_array_dask.shape == match_array.shape 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:20,代碼來源:test_dask_tools.py

示例13: test_intensity_peaks_image_disk_r

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_intensity_peaks_image_disk_r(self):
        numpy_array = np.zeros((50, 50))
        numpy_array[27, 29] = 2
        numpy_array[11, 15] = 1
        image = da.from_array(numpy_array, chunks=(50, 50))
        peak = np.array([[27, 29], [11, 15]], np.int32)
        peak_dask = da.from_array(peak, chunks=(1, 1))
        disk_r0 = 1
        disk_r1 = 2
        intensity0 = dt._intensity_peaks_image_single_frame(image, peak_dask, disk_r0)
        intensity1 = dt._intensity_peaks_image_single_frame(image, peak_dask, disk_r1)

        assert intensity0[0].all() == np.array([27.0, 29.0, 2 / 9]).all()
        assert intensity0[1].all() == np.array([11.0, 15.0, 1 / 9]).all()
        assert intensity1[0].all() == np.array([27.0, 29.0, 2 / 25]).all()
        assert intensity1[1].all() == np.array([11.0, 15.0, 1 / 25]).all()
        assert intensity0.shape == intensity1.shape == (2, 3) 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:19,代碼來源:test_dask_tools.py

示例14: test_intensity_peaks_chunk

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_intensity_peaks_chunk(self):
        numpy_array = np.zeros((2, 2, 50, 50))
        numpy_array[:, :, 27, 27] = 1

        peak_array = np.zeros(
            (numpy_array.shape[0], numpy_array.shape[1]), dtype=np.object
        )
        for index in np.ndindex(numpy_array.shape[:-2]):
            islice = np.s_[index]
            peak_array[islice] = np.asarray([(27, 27)])

        dask_array = da.from_array(numpy_array, chunks=(1, 1, 25, 25))
        peak_array_dask = da.from_array(peak_array, chunks=(1, 1))
        disk_r = 2
        intensity_array = dt._intensity_peaks_image_chunk(
            dask_array, peak_array_dask, disk_r
        )

        assert intensity_array.shape == peak_array_dask.shape 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:21,代碼來源:test_dask_tools.py

示例15: test_intensity_peaks_dask

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import from_array [as 別名]
def test_intensity_peaks_dask(self):
        numpy_array = np.zeros((10, 10, 50, 50))
        numpy_array[:, :, 27, 27] = 1

        peak_array = np.zeros(
            (numpy_array.shape[0], numpy_array.shape[1]), dtype=np.object
        )
        for index in np.ndindex(numpy_array.shape[:-2]):
            islice = np.s_[index]
            peak_array[islice] = np.asarray([(27, 27)])

        dask_array = da.from_array(numpy_array, chunks=(5, 5, 5, 5))
        dask_peak_array = da.from_array(peak_array, chunks=(5, 5))

        disk_r = 2
        intensity_array = dt._intensity_peaks_image(dask_array, dask_peak_array, disk_r)
        intensity_array_computed = intensity_array.compute()
        assert intensity_array_computed.shape == peak_array.shape 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:20,代碼來源:test_dask_tools.py


注:本文中的dask.array.from_array方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。