How to use the numpy.zeros function in numpy

To help you get started, we’ve selected a few numpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Algomorph / LevelSetFusion-Python / archive / warpAKAP2D.py View on Github external
def main():
    image = cv2.imread("test_image1.png")
    step_size_px = 10
    vertex_row_count = image.shape[0] // step_size_px
    vertex_col_count = image.shape[1] // step_size_px
    vertex_count = vertex_row_count * vertex_col_count

    face_row_count = vertex_row_count - 1
    face_col_count = vertex_col_count - 1

    print("Grid size: ", vertex_row_count, " x ", vertex_col_count)
    print("Vertex count: ", vertex_count)
    warp_coefficient_count = 2 * vertex_count

    # G = np.zeros((2 * face_col_count * face_row_count, vertex_col_count * vertex_row_count), np.float32)
    G = np.zeros(
        (face_col_count * vertex_row_count + face_row_count * vertex_col_count, vertex_count),
        np.float32)

    ix_G_row = 0
    for ix_dx_row in range(vertex_row_count):
        for ix_dx_col in range(face_col_count):
            col_index0 = vertex_col_count * ix_dx_row + ix_dx_col
            col_index1 = col_index0 + 1
            G[ix_G_row, col_index0] = -1.0
            G[ix_G_row, col_index1] = 1.0
            ix_G_row += 1
    for ix_dy_row in range(face_row_count):
        for ix_dy_col in range(vertex_col_count):
            col_index0 = vertex_col_count * ix_dy_row + ix_dy_col
            col_index1 = col_index0 + vertex_col_count
            G[ix_G_row, col_index0] = -1.0
github robmcmullen / asmgen / asmgen.py View on Github external
def split_bit_stream(self, width, bit_stream, high_bits):
        # print bit_stream
        # print high_bits

        # Split bitstream into bytes
        byte_width = width // 7
        bit_pos = 0
        filler_bit = "0"
        byte_splits = np.zeros((byte_width), dtype=np.uint8)

        for byte_index in range(byte_width):
            remaining_bits = len(bit_stream) - bit_pos
                
            bit_chunk = ""
            
            if remaining_bits < 0:
                bit_chunk = filler_bit * 7
            else:   
                if remaining_bits < 7:
                    bit_chunk = bit_stream[bit_pos:]
                    bit_chunk += filler_bit * (7-remaining_bits)
                else:   
                    bit_chunk = bit_stream[bit_pos:bit_pos+7]
            
            bit_chunk = bit_chunk[::-1]
github NeuromorphicProcessorProject / snn_toolbox / snntoolbox / datasets / aedat / avi_to_lmdb.py View on Github external
def write_categ_lmdb(workfile, categories, LMDB_path, gray):
    """Given a workfile containing the AVI movies and the labels for each
    frame, this function creates an LMDB for each classification category.
    """
    # Open databases
    categ_db = []
    for idx, categ in enumerate(categories):
        categ_db.append(
            lmdb.open(os.path.join(LMDB_path, categ), map_size=int(1e12),
                      map_async=True, writemap=True, meminit=False))
    curr_idx = np.zeros(len(categories), dtype='int')
    with open(workfile, 'r') as f:
        for line in f.readlines():
            # Load work to do
            avi_file, label_file = line.strip().split('    ')

            # Convert to data
            file_frames = avi_to_frame_list(avi_file, gray)
            file_labels = label_file_to_labels(label_file)

            # Quick check the lengths
            assert len(file_frames) == len(file_labels), \
                'Frames and Labels do not match in length!'

            # Write data in each LMDB corresponding to the .avi category
            db_label = avi_file.split("/")[-1].split("_")[0]
            index = categories.index(db_label)
github rosswhitfield / ase / ase / calculators / vasp / vasp2.py View on Github external
def _read_magnetic_moments(self, lines=None):
        """Read magnetic moments from OUTCAR.
        Only reads the last occurrence. """
        if not lines:
            lines = self.load_file('OUTCAR')

        magnetic_moments = np.zeros(len(self.atoms))
        magstr = 'magnetization (x)'

        # Search for the last occurrence
        nidx = -1
        for n, line in enumerate(lines):
            if magstr in line:
                nidx = n

        # Read that occurrence
        if nidx > -1:
            for m in range(len(self.atoms)):
                magnetic_moments[m] = float(lines[nidx + m + 4].split()[4])
        return magnetic_moments[self.resort]
github cctbx / cctbx_project / simtbx / diffBragg / load_ls49.py View on Github external
def strong_spot_mask(refl_tbl, img_size):
    """note only works for strong spot reflection tables
    img_size is slow-scan, fast-scan"""
    import numpy as np
    from dials.algorithms.shoebox import MaskCode
    Nrefl = len(refl_tbl)
    masks = [refl_tbl[i]['shoebox'].mask.as_numpy_array()
             for i in range(Nrefl)]
    code = MaskCode.Foreground.real

    x1, x2, y1, y2, z1, z2 = zip(*[refl_tbl[i]['shoebox'].bbox
                                   for i in range(Nrefl)])
    spot_mask = np.zeros(img_size, bool)
    for i1, i2, j1, j2, M in zip(x1, x2, y1, y2, masks):
        slcX = slice(i1, i2, 1)
        slcY = slice(j1, j2, 1)
        spot_mask[slcY, slcX] = M & code == code
    return spot_mask
github qmlcode / qml / qml / aglaia / aglaia.py View on Github external
"""
        # Obtaining the xyz and the nuclear charges from the compounds
        xyzs = []
        zs = []
        max_n_atoms = 0

        for compound in self.compounds:
            xyzs.append(compound.coordinates)
            zs.append(compound.nuclear_charges)
            if len(compound.nuclear_charges) > max_n_atoms:
                max_n_atoms = len(compound.nuclear_charges)

        n_samples = len(xyzs)

        # Padding the xyz and the nuclear charges
        padded_xyz = np.zeros((n_samples, max_n_atoms, 3))
        padded_zs = np.zeros((n_samples, max_n_atoms))

        for i in range(n_samples):
            current_n_atoms = xyzs[i].shape[0]
            padded_xyz[i, :current_n_atoms, :] = xyzs[i]
            padded_zs[i, :current_n_atoms] = zs[i]

        return padded_xyz, padded_zs
github navneet-nmk / pytorch-rl / models / infogan.py View on Github external
def _noise_sample(self, cat_c, con_c, noise, bs):
        idx = np.random.randint(10, size=bs)
        c = np.zeros((bs, 10))
        c[range(bs), idx] = 1.0

        cat_c.data.copy_(torch.Tensor(c))
        con_c.data.uniform_(-self.noise_uniform, self.noise_uniform)
        noise.data.uniform_(-self.noise_uniform, self.noise_uniform)
        z = torch.cat([noise, cat_c, con_c], 1).view(-1, (self.noise_dim+self.cat_dim+self.cont_dim))

        return z, idx
github xuxie1031 / VRGraspIRLEnv / IRLs / scripts / PlayIRL / IRL / kernelUtils.py View on Github external
def kernel(x1, x2, k_name='ARD', **kwargs):
    is_not_diagnol = len(x1) != len(x2)
    i_neq_j = np.ones((len(x2), 1))

    K = np.zeros((len(x1), len(x2)))
    for i in range(len(x1)):
        xi = x1[i, :]
        if not is_not_diagnol:
            i_neq_j = np.asarray(i != np.arange(len(x2)), dtype=np.float).reshape(-1, 1)
        K[i, :] = kernel_calc(xi, x2, k_name='ARD', lambd=kwargs['lambd'], beta=kwargs['beta'], i_neq_j=i_neq_j, sigma_sq=kwargs['sigma_sq'])

    return K
github mcahny / Deep-Video-Inpainting / utils.py View on Github external
def make_color_wheel():
    """
    Generate color wheel according Middlebury color code
    :return: Color wheel
    """
    RY = 15
    YG = 6
    GC = 4
    CB = 11
    BM = 13
    MR = 6

    ncols = RY + YG + GC + CB + BM + MR

    colorwheel = np.zeros([ncols, 3])

    col = 0

    # RY
    colorwheel[0:RY, 0] = 255
    colorwheel[0:RY, 1] = np.transpose(np.floor(255*np.arange(0, RY) / RY))
    col += RY

    # YG
    colorwheel[col:col+YG, 0] = 255 - np.transpose(np.floor(255*np.arange(0, YG) / YG))
    colorwheel[col:col+YG, 1] = 255
    col += YG

    # GC
    colorwheel[col:col+GC, 1] = 255
    colorwheel[col:col+GC, 2] = np.transpose(np.floor(255*np.arange(0, GC) / GC))
github prakashpandey9 / BicycleGAN / model.py View on Github external
self.step += 1
			input_img = np.expand_dims(img_A, axis=0)
			true_img = np.expand_dims(img_B, axis=0)
			images_random = []
			images_random.append(input_img)
			images_random.append(true_img)
			images_linear = []
			images_linear.append(input_img)
			images_linear.append(true_img)

			for i in range(23):
				z = np.random.normal(size=(1, self.Z_dim))
				LR_desired_img = self.sess.run(self.LR_desired_img, feed_dict={self.image_A: input_img, self.z: z})
				images_random.append(LR_desired_img)

				z = np.zeros((1, self.Z_dim))
				z[0][0] = (i / 23.0 - 0.5) * 2.0
				LR_desired_img = self.sess.run(self.LR_desired_img, feed_dict={self.image_A: input_img, self.z: z})
				images_linear.append(LR_desired_img)

			image_rows = []
			for i in range(5):
				image_rows.append(np.concatenate(images_random[i*5:(i+1)*5], axis=2))
			images = np.concatenate(image_rows, axis=1)
			images = np.squeeze(images, axis=0)
			scipy.misc.imsave(os.path.join(base_dir, 'random_{}.jpg'.format(step)), images)

			image_rows = []
			for i in range(5):
				image_rows.append(np.concatenate(images_linear[i*5:(i+1)*5], axis=2))
			images = np.concatenate(image_rows, axis=1)
			images = np.squeeze(images, axis=0)