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


Python array.zeros方法代碼示例

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


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

示例1: weighting

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def weighting(spec_dist, temp_dist, comb_dist, similar_pixels_filtered):
    # Assign max weight (1) when the temporal or spectral distance is zero
    zero_spec_dist = da.where(spec_dist[:,mid_idx][:,None] == 1, 1, 0)
    zero_temp_dist = da.where(temp_dist[:,mid_idx][:,None] == 1, 1, 0)
    zero_dist_mid = da.where((zero_spec_dist == 1), 
                             zero_spec_dist, zero_temp_dist)
    shape = da.subtract(spec_dist.shape,(0,1))
    zero_dist = da.zeros(shape, chunks=(spec_dist.shape[0],shape[1]))
    zero_dist = da.insert(zero_dist, [mid_idx], zero_dist_mid, axis=1)
    weights = da.where((da.sum(zero_dist,1)[:,None] == 1), zero_dist, comb_dist)
    
    # Calculate weights only for the filtered spectrally similar pixels
    weights_filt = weights*similar_pixels_filtered
    
    # Normalize weights
    norm_weights = da.rechunk(weights_filt/(da.sum(weights_filt,1)[:,None]), 
                              chunks = spec_dist.chunksize)
    
    print ("Done weighting!", norm_weights)
    
    return norm_weights


# Derive fine resolution reflectance for the day of prediction 
開發者ID:nmileva,項目名稱:starfm4py,代碼行數:26,代碼來源:starfm4py.py

示例2: test_simple

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_simple(self):
        peak_array = np.empty((2, 3), dtype=np.object)
        peak_array[0, 0] = [[2, 4]]
        peak_array[0, 1] = [[8, 2]]
        peak_array[0, 2] = [[1, 8]]
        peak_array[1, 0] = [[3, 1]]
        peak_array[1, 1] = [[9, 1]]
        peak_array[1, 2] = [[6, 3]]
        s = Diffraction2D(np.zeros(shape=(2, 3, 10, 10)))
        marker_list = mt._get_4d_points_marker_list(
            peak_array, s.axes_manager.signal_axes, color="red"
        )
        mt._add_permanent_markers_to_signal(s, marker_list)
        assert len(marker_list) == 1
        marker = marker_list[0]
        assert marker.marker_properties["color"] == "red"
        s.plot()
        for iy, ix in np.ndindex(peak_array.shape[:2]):
            peak = peak_array[iy, ix]
            s.axes_manager.indices = (ix, iy)
            print(peak, (iy, ix), marker)
            assert marker.get_data_position("x1") == peak[0][1]
            assert marker.get_data_position("y1") == peak[0][0] 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:25,代碼來源:test_marker_tools.py

示例3: test_peak_finding_to_marker

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_peak_finding_to_marker():
    data = np.zeros(shape=(3, 2, 10, 12))
    data[0, 0, 2, 7] = 1
    data[0, 1, 7, 3] = 1
    data[1, 0, 4, 6] = 1
    data[1, 1, 2, 3] = 1
    data[2, 0, 3, 6] = 1
    data[2, 1, 2, 2] = 1
    s = Diffraction2D(data)
    peak_array = s.find_peaks_lazy(
        min_sigma=0.1, max_sigma=2, threshold=0.01, lazy_result=False
    )
    marker_list = mt._get_4d_points_marker_list(peak_array, s.axes_manager.signal_axes)
    assert len(marker_list) == 1
    marker = marker_list[0]
    mt._add_permanent_markers_to_signal(s, marker_list)
    s.plot()
    for ix, iy in s.axes_manager:
        px, py = marker.get_data_position("x1"), marker.get_data_position("y1")
        value = s.inav[ix, iy].isig[int(px), int(py)].data[0]
        assert value == 1.0 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:23,代碼來源:test_marker_tools.py

示例4: test_single_frame_multiple_peak

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_single_frame_multiple_peak(self):
        image = np.zeros(shape=(200, 100), dtype=np.float64)
        peak_list = [[120, 76], [23, 54], [32, 78], [10, 15]]
        for x, y in peak_list:
            image[x, y] = 654
        min_sigma, max_sigma, sigma_ratio = 2, 5, 5
        threshold, overlap = 0.01, 1
        peaks = dt._peak_find_dog_single_frame(
            image,
            min_sigma=min_sigma,
            max_sigma=max_sigma,
            sigma_ratio=sigma_ratio,
            threshold=threshold,
            overlap=overlap,
        )
        assert len(peaks) == len(peak_list)
        for peak in peaks.tolist():
            assert peak in peak_list 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:20,代碼來源:test_dask_tools.py

示例5: test_single_frame_threshold

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_single_frame_threshold(self):
        image = np.zeros(shape=(200, 100), dtype=np.float64)
        image[54, 29] = 100
        image[123, 54] = 20
        min_sigma, max_sigma, sigma_ratio, overlap = 2, 5, 5, 1
        peaks0 = dt._peak_find_dog_single_frame(
            image,
            min_sigma=min_sigma,
            max_sigma=max_sigma,
            sigma_ratio=sigma_ratio,
            threshold=0.01,
            overlap=overlap,
        )
        assert len(peaks0) == 2
        peaks1 = dt._peak_find_dog_single_frame(
            image,
            min_sigma=min_sigma,
            max_sigma=max_sigma,
            sigma_ratio=sigma_ratio,
            threshold=0.05,
            overlap=overlap,
        )
        assert len(peaks1) == 1 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:25,代碼來源:test_dask_tools.py

示例6: test_single_frame_min_sigma

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_single_frame_min_sigma(self):
        image = np.zeros(shape=(200, 100), dtype=np.float64)
        image[54, 29] = 100
        image[54, 32] = 100
        max_sigma, sigma_ratio = 5, 5
        threshold, overlap = 0.01, 0.1
        peaks0 = dt._peak_find_dog_single_frame(
            image,
            min_sigma=1,
            max_sigma=max_sigma,
            sigma_ratio=sigma_ratio,
            threshold=threshold,
            overlap=overlap,
        )
        assert len(peaks0) == 2
        peaks1 = dt._peak_find_dog_single_frame(
            image,
            min_sigma=2,
            max_sigma=max_sigma,
            sigma_ratio=sigma_ratio,
            threshold=threshold,
            overlap=overlap,
        )
        assert len(peaks1) == 1 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:26,代碼來源:test_dask_tools.py

示例7: test_chunk

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_chunk(self):
        data = np.zeros(shape=(2, 3, 200, 100), dtype=np.float64)
        data[0, 0, 50, 20] = 100
        data[0, 1, 51, 21] = 100
        data[0, 2, 52, 22] = 100
        data[1, 0, 53, 23] = 100
        data[1, 1, 54, 24] = 100
        data[1, 2, 55, 25] = 100
        min_sigma, max_sigma, sigma_ratio = 0.08, 1, 1.76
        threshold, overlap = 0.06, 0.01
        peaks = dt._peak_find_dog_chunk(
            data,
            min_sigma=min_sigma,
            max_sigma=max_sigma,
            sigma_ratio=sigma_ratio,
            threshold=threshold,
            overlap=overlap,
        )
        assert peaks[0, 0][0].tolist() == [50, 20]
        assert peaks[0, 1][0].tolist() == [51, 21]
        assert peaks[0, 2][0].tolist() == [52, 22]
        assert peaks[1, 0][0].tolist() == [53, 23]
        assert peaks[1, 1][0].tolist() == [54, 24]
        assert peaks[1, 2][0].tolist() == [55, 25] 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:26,代碼來源:test_dask_tools.py

示例8: test_chunk_peak

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

        peak_array = np.zeros(
            (numpy_array.shape[0], numpy_array.shape[1], 1, 1), 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][0, 0] = np.asarray([(27, 27)])
            real_array[islice] = np.asarray([(25, 25)])

        square_size = 12

        data = dt._peak_refinement_centre_of_mass_chunk(
            numpy_array, peak_array, square_size
        )
        assert data.shape == (2, 2)
        assert np.sum(data - real_array).sum() == 0 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:22,代碼來源:test_dask_tools.py

示例9: test_dask_array

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [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

示例10: test_array_different_dimensions

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [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

示例11: test_intensity_peaks_image_disk_r

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [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

示例12: test_intensity_peaks_chunk

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [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

示例13: test_angles_across_pi

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_angles_across_pi(self):
        s = Signal2D(np.zeros((100, 100)))
        s.axes_manager[0].offset, s.axes_manager[1].offset = -49.5, -49.5
        mask0 = pst._get_angle_sector_mask(s, 0.5 * np.pi, 1.5 * np.pi)
        assert np.invert(mask0[:, 0:50]).all()
        assert mask0[:, 50:].all()

        mask1 = pst._get_angle_sector_mask(s, 2.5 * np.pi, 3.5 * np.pi)
        assert np.invert(mask1[:, 0:50]).all()
        assert mask1[:, 50:].all()

        mask2 = pst._get_angle_sector_mask(s, 4.5 * np.pi, 5.5 * np.pi)
        assert np.invert(mask2[:, 0:50]).all()
        assert mask2[:, 50:].all()

        mask3 = pst._get_angle_sector_mask(s, -3.5 * np.pi, -2.5 * np.pi)
        assert np.invert(mask3[:, 0:50]).all()
        assert mask3[:, 50:].all() 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:20,代碼來源:test_pixelated_stem_tools.py

示例14: test_angles_across_zero

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_angles_across_zero(self):
        s = Signal2D(np.zeros((100, 100)))
        s.axes_manager[0].offset, s.axes_manager[1].offset = -50, -50
        mask0 = pst._get_angle_sector_mask(s, -0.5 * np.pi, 0.5 * np.pi)
        assert mask0[:, 0:50].all()
        assert np.invert(mask0[:, 50:]).all()

        mask1 = pst._get_angle_sector_mask(s, 1.5 * np.pi, 2.5 * np.pi)
        assert mask1[:, 0:50].all()
        assert np.invert(mask1[:, 50:]).all()

        mask2 = pst._get_angle_sector_mask(s, 3.5 * np.pi, 4.5 * np.pi)
        assert mask2[:, 0:50].all()
        assert np.invert(mask2[:, 50:]).all()

        mask3 = pst._get_angle_sector_mask(s, -4.5 * np.pi, -3.5 * np.pi)
        assert mask3[:, 0:50].all()
        assert np.invert(mask3[:, 50:]).all() 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:20,代碼來源:test_pixelated_stem_tools.py

示例15: test_copy_all_axes_manager

# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import zeros [as 別名]
def test_copy_all_axes_manager(self):
        s = Signal2D(np.zeros((5, 40, 50)))
        s_new = Signal2D(np.zeros_like(s.data))
        sa_ori = s.axes_manager
        sa_ori[0].scale = 0.2
        sa_ori[1].scale = 2.2
        sa_ori[2].scale = 0.02
        sa_ori[0].offset = 321
        sa_ori[1].offset = -232
        sa_ori[2].offset = 32
        pst._copy_signal_all_axes_metadata(s, s_new)
        sa_new = s_new.axes_manager
        assert sa_ori[0].scale == sa_new[0].scale
        assert sa_ori[1].scale == sa_new[1].scale
        assert sa_ori[2].scale == sa_new[2].scale
        assert sa_ori[0].offset == sa_new[0].offset
        assert sa_ori[1].offset == sa_new[1].offset
        assert sa_ori[2].offset == sa_new[2].offset 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:20,代碼來源:test_pixelated_stem_tools.py


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