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


Python random.random_integers方法代碼示例

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


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

示例1: add_padding

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def add_padding(packet, bytes_padding:int = 0, user_padding:bool=True, rnd:bool = False):
    """
    Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes, if called by the user.
    :param packet: the packet that will be extended with the additional payload
    :param bytes_padding: the amount of bytes that will be appended to the packet. Capped to 100,
    if called by the user.
    :param user_padding: true, if the function add_padding by the user and not within the code
    :param rnd: adds a random padding between 0 and bytes_padding, if true
    :return: the initial packet, extended with the wanted amount of bytes of padding
    """

    if user_padding == True and bytes_padding > 100:
        bytes_padding = 100

    if rnd is True:
        r = int(round(bytes_padding / 4))                  # sets bytes_padding to any number between 0 and
        bytes_padding = random2.random_integers(0, r) * 4  # bytes_padding, that's dividable by 4
    payload = generate_payload(bytes_padding)
    packet[Raw].load += Raw(load=payload).load
    return packet 
開發者ID:tklab-tud,項目名稱:ID2T,代碼行數:22,代碼來源:Generator.py

示例2: __define_suppliers

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def __define_suppliers(self):

        self.hierarchy['Suppliers'] = []
        for SupplierID in range(1, n_suppliers + 1):
            supplier_dict = {}
            supplier_dict['SupplierID'] = str(SupplierID)
            supplier_dict['SupplierName'] = 'Supplier ' + supplier_dict['SupplierID']
            supplier_dict['ShippingCost'] = uniform(min_shipping_cost, max_shipping_cost)
            supplier_dict['MinShippingVolume'] = uniform(min_min_shipping_volume, max_min_shipping_volume)
            supplier_dict['MaxShippingVolume'] = supplier_dict['MinShippingVolume'] + uniform(min_shipping_volume_interval, max_shipping_volume_interval)
            supplier_dict['FixedOrderSize'] = int(random_integers(min_fixed_order_size, max_fixed_order_size))
            supplier_dict['PurchaseCostBudget'] = uniform(min_purchase_cost_budget, max_purchase_cost_budget)

            self.hierarchy['Suppliers'].append(supplier_dict)


    # definitions of storage 
開發者ID:Azure,項目名稱:cortana-intelligence-inventory-optimization,代碼行數:19,代碼來源:Simulator.py

示例3: corrupt_image

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def corrupt_image(img, MAR_prob=0, min_rects=0, max_rects=0, min_width=0, max_width=0, apply_to_all_channels=False):
    def generate_channel_mask():
        mask = np.zeros(img.shape[0:2], dtype=np.bool)
        if MAR_prob > 0:
            mask[(random_sample(mask.shape) < MAR_prob)] = True
        if max_rects > 0 and max_width > 0:
            h, w = mask.shape
            num_rects = random_integers(min_rects, max_rects)
            for i in range(num_rects):
                px1 = random_integers(0, w - min(max(min_width, 1), w))
                py1 = random_integers(0, h - min(max(min_width, 1), h))
                px2 = px1 + min_width + random_integers(0, max(min(w - px1 - min_width, max_width - min_width), 0));
                py2 = py1 + min_width + random_integers(0, max(min(h - py1 - min_width, max_width - min_width), 0));
                if px1 <= px2 and py1 <= py2:
                    mask[py1:py2, px1:px2] = True
                else:
                    # One of the sides has length 0, so we should remove any pixels4
                    pass
        return mask
    new_img = img.copy()
    channels = 1 if len(new_img.shape) == 2 else new_img.shape[-1]
    global_mask = np.zeros(img.shape, dtype=np.bool)
    if channels == 1 or apply_to_all_channels:
        mask = generate_channel_mask()
        if channels == 1:
            global_mask[:, :] = mask
        else:
            for i in xrange(channels):
                global_mask[:, :, i] = mask
    else:
        global_mask = np.zeros(img.shape, dtype=np.bool)
        for i in xrange(channels):
            global_mask[:,:,i] = generate_channel_mask()
    new_img[global_mask] = 0
    return (new_img, 1.0 * global_mask)

# Process command line inputs 
開發者ID:HUJI-Deep,項目名稱:Generative-ConvACs,代碼行數:39,代碼來源:generate_missing_data.py

示例4: __define_brands_products

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def __define_brands_products(self):
        
        # definition of brands and products
        self.hierarchy['Brands'] = []
        for BrandID in range(1, n_brands + 1):
            brand_dict = {}
            brand_dict['BrandID'] = str(BrandID)
            brand_dict['BrandName'] = 'Brand ' + brand_dict['BrandID']
            brand_dict['Desirability'] = uniform(min_brand_desirability, max_brand_desirability)

            # definition of products of the given brand in the given store department
            brand_dict['Products'] = []

            # For the time being, only one product per brand. This will change in the future 
            product_dict = {}
            product_dict['ProductID'] =  brand_dict['BrandID'] + '_1'
            product_dict['ProductName'] =  brand_dict['BrandName'] + ' Product ' + product_dict['ProductID']
            product_dict['ProductVolume'] = uniform(min_product_volume, max_product_volume)
            product_dict['MSRP'] = 0 # will be updated later on, based on the purchase cost
            if BrandID <= n_brands/2 or choice([-1,1]) == 1: # first half of the brands have perishable products
                                                             # some brands in the second half also have perishable products
                product_dict['ShelfLife'] = str(random_integers(min_shelf_life, max_shelf_life)) + ' days'
            else:
                product_dict['ShelfLife'] = '10000 days'

            brand_dict['Products'].append(product_dict)

            self.hierarchy['Brands'].append(brand_dict)


    # definitions of suppliers 
開發者ID:Azure,項目名稱:cortana-intelligence-inventory-optimization,代碼行數:33,代碼來源:Simulator.py

示例5: __store_product_storage

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def __store_product_storage(self):

        product_storage = []
        for StorageID in range(1, n_storage_spaces + 1):
            start_brand = int((StorageID - 1) * n_brands / n_storage_spaces)
            end_brand = int(StorageID * n_brands / n_storage_spaces)
            storage_dict = {}
            storage_dict['StorageID'] = StorageID
            storage_dict['Products'] = []
  
            # place products in a given storage space
            for BrandID in range(start_brand, end_brand):
                for product in self.hierarchy['Brands'][BrandID]['Products']:
                    product_storage_dict = {}
                    product_storage_dict['ProductID'] = product['ProductID']
                    product_storage_dict['StorageCost'] = uniform(min_storage_cost, max_storage_cost)
                    product_storage_dict['MissedSaleCost'] = uniform(min_missed_sale_cost, max_missed_sale_cost)
                    product_storage_dict['MinInventorySize'] = int(random_integers(min_min_inventory_size, max_min_inventory_size))
                    product_storage_dict['MaxInventorySize'] = product_storage_dict['MinInventorySize'] + int(random_integers(min_inventory_size_interval, max_inventory_size_interval))

                    storage_dict['Products'].append(product_storage_dict)

            product_storage.append(storage_dict)

        return product_storage


    # definitions of suppliers of products 
開發者ID:Azure,項目名稱:cortana-intelligence-inventory-optimization,代碼行數:30,代碼來源:Simulator.py

示例6: __store_product_supplier

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def __store_product_supplier(self):

        product_supplier = []
        for SupplierID in range(1, n_suppliers + 1): 
            start_brand = int((SupplierID - 1) * n_brands / n_suppliers)
            end_brand = int(SupplierID * n_brands / n_suppliers)
            supplier_dict = {}
            supplier_dict['SupplierID'] = SupplierID
            supplier_dict['Products'] = []

            # place products in a given storage space
            for BrandID in range(start_brand, end_brand):
                for product in self.hierarchy['Brands'][BrandID]['Products']:
                    product_supplier_dict = {}
                    product_supplier_dict['ProductID'] = product['ProductID']
                    product_supplier_dict['LeadTime'] = int(random_integers(min_lead_time, max_lead_time))
                    product_supplier_dict['LeadTimeConfidenceInterval'] = int(random_integers(min_lead_time_conf_interval, max_lead_time_conf_interval))
                    product_supplier_dict['MinOrderQuantity'] = int(random_integers(min_min_order_quantity, max_min_order_quantity))
                    product_supplier_dict['MaxOrderQuantity'] = product_supplier_dict['MinOrderQuantity'] + int(random_integers(min_order_quantity_interval, max_order_quantity_interval))
                    product_supplier_dict['QuantityMultiplier'] = int(random_integers(min_quantity_multiplier, max_quantity_multiplier))
                    product_supplier_dict['Cost'] = uniform(min_purchase_cost, max_purchase_cost)
                    product_supplier_dict['BackorderCost'] = product_supplier_dict['Cost'] * uniform(min_backorder_multiplier, max_backorder_multiplier)
                    product_supplier_dict['PurchaseCostBudget'] = product_supplier_dict['Cost'] * uniform(min_purchase_cost_budget_multiplier, max_purchase_cost_budget_multiplier)
                    product_supplier_dict['ShippingCost'] = product_supplier_dict['Cost'] * uniform(min_shipping_multiplier, max_shipping_multiplier)
                    product_supplier_dict['ShipmentFreq'] = str(random_integers(min_ordering_frequency, max_ordering_frequency)) + " days"
                    product_supplier_dict['ServiceLevel'] = uniform(min_service_level, max_service_level)

                    supplier_dict['Products'].append(product_supplier_dict)

            product_supplier.append(supplier_dict)

        return product_supplier


    # Create static data: definitions of stores, storage spaces, products and suppliers 
開發者ID:Azure,項目名稱:cortana-intelligence-inventory-optimization,代碼行數:37,代碼來源:Simulator.py

示例7: __compute_arrivals

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def  __compute_arrivals(self):
         min_order = max(1,self.min_order_quantity)
         if self.max_order_quantity < 0:
             max_order = 10000
         else:
             max_order = min(10000, self.max_order_quantity)
         order_arrival = int(random_integers(min_order, max_order))
         if self.quantity_multiplier > 0:
             return max(min_order, order_arrival - (order_arrival % self.quantity_multiplier))     
         else:
             return order_arrival 
開發者ID:Azure,項目名稱:cortana-intelligence-inventory-optimization,代碼行數:13,代碼來源:Simulator.py

示例8: step

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import random_integers [as 別名]
def step(self):
        self.mcbar_attempts += 1

        # Get energy, volume for current system configuration
        E0 = self.atoms.get_potential_energy()
        V0 = self.atoms.get_volume()
        cell0 = self.atoms.get_cell()

        dV = np.zeros(3)

        # Random change to fractional unit cell volume in range (-0.5*dV_max,0.5*dV_max)
        if self.iso:
            dV[:] = (rand.random() - 0.5) * self.dV_max
        else:
            dim = rand.random_integers(0,2)
            dV[dim] = (rand.random() - 0.5) * self.dV_max

        rmu = (1. + dV) ** (1./3.)
        # Is this correct for non-rectangular cells?
        cell = cell0.copy()
        cell[0] *= rmu[0]
        cell[1] *= rmu[1]
        cell[2] *= rmu[2]
        # Scale system to new unit cell and get new energy, volume
        self.atoms.set_cell(cell,scale_atoms=True)

        E = self.atoms.get_potential_energy()
        V = self.atoms.get_volume()
        
        pv_work = self.pres * (V - V0) * PCONV

        mc_term = np.exp((E - E0 + pv_work) * self.beta + self.natoms * np.log(rmu[0]*rmu[1]*rmu[2]))
        mc_check = rand.random()

        # Monte Carlo condition check
        if mc_check < mc_term:
            self.mcbar_successes += 1
        else:
            # On failure, revert the system to previous volume
            self.atoms.set_cell(cell0,scale_atoms=True)

        # Check if we are succeeding too often or not often enough, and change dV_max if so
        if self.mcbar_attempts % self.dV_interval == 0:
            if self.mcbar_successes >= 0.75 * self.mcbar_attempts:
                print("MC BAR INCREASE DVMAX",self.mcbar_attempts,self.mcbar_successes)
                self.dV_max *= self.dV_scale
                self.mcbar_attempts = 0
                self.mcbar_successes = 0
            elif self.mcbar_successes <= 0.25 * self.mcbar_attempts:
                print("MC BAR DECREASE DVMAX:",self.mcbar_attempts,self.mcbar_successes)
                self.dV_max /= self.dV_scale
                self.mcbar_attempts = 0
                self.mcbar_successes = 0 
開發者ID:isayev,項目名稱:ASE_ANI,代碼行數:55,代碼來源:ase_mc_npt.py


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