def __init__(self, curva_id, **kwargs): #variáveis básicas self.curva_id = curva_id self.titulo = "" self.descricao = "" self.title = "" self.description = "" self.ndim = 0 self.tags = [] # self.x = np.array() # TODO: abstrair melhor essa merda self.ue = [] # vetor de ue de acordo com os tags ue = {'original': '', 'used': ''} self.val = None # self.tags_ = tag self.metadata = [] metadata = { 'x_tag': None, 'y_tag': None, 'z_tag': None, 'x_options': {}, 'y_options': {}, 'z_options': {} } self.x_values = np.Array() self.y_values = np.Array() self.z_values = np.Array() if (kwargs): for k, v in kwargs.items(): setattr(self, k, v)
def sparse_pearsonr(a, b): length = a.shape[1] mean_a = a.mean() mean_b = b.mean() mean_product_ab = mean_a * mean_b mean_product_aa = mean_a ** 2 mean_product_bb = mean_b ** 2 am = a - np.Array([a.mean()] * length) bm = b - np.Array([b.mean()] * length) return cosine_similarity(am, bm)
def _get_data(self): try: ret = self.section.data.data_points #self.pointsx = ret[:, 0] #self.pointsy = ret[:, 1] self.plotdata.set_data('x', ret[:, 0]) self.plotdata.set_data('y', ret[:, 1]) return ret except AttributeError: return numpy.Array([[], []])
def __init__(self, *coeffs): """Creates a Polynomial with the coefficients, starting with the constant""" self.coeffs = np.Array(coeffs) self.order = len(self.coeffs) - 1
def main(): arr, mode1 = load_img_arr('work/form1.1.npy') image_data_size = arr.size thread_x, thread_y, thread_z = GPU_ATTRIBUTES['MAX_THREADS_PER_BLOCK']/GPU_ATTRIBUTES['MULTIPROCESSOR_COUNT'], 1, 1 block_size = (thread_x, thread_y, thread_z) # arr <- all rows # arr[0] <- pixels in first row # arr[0][0] <- first pixel in first row (RGB[A]) #TODO: # make a strip of images up to max images, max grid dim, or max image count # if there are images left over, start making another strip (same conditions as above) # if we finished a whole strip, add the strip to the existing strips # repeat until all images are used up or we have more strips than that grid dim pairs_processed = 0 total_image_pairs = 50 while pairs_processed < total_image_pairs: free_memory = cuda.mem_get_info()[0] half_memory = free_memory / 2 max_group_count = (half_memory / image_data_size) # number of image pairs that can be loaded y_strip_count = 0 group_count = 0 strip1 = numpy.Array() strip2 = numpy.Array() while group_count < max_group_count and y_strip_count < GPU_ATTRIBUTES['MAX_GRID_DIM_Y']: i1 = load_img_arr('work/form1.%d.npy' % (pairs_processed+1)) i2 = load_img_arr('work/form2.%d.npy' % (pairs_processed+1)) group_count += 1 pairs_processed += 1 x_strip_count = 0 # make strip here images_processed = 0 image_count = 50 block_y = 1 while images_processed < image_count: free_memory = cuda.mem_get_info()[0] half_memory = free_memory / 2 image_group_count = (half_memory / image_data_size) - 1 # number of image pairs that can be loaded block1 = load_img_arr('work/form1.%d.npy'%(images_processed+1))[0] block2 = load_img_arr('work/form2.%d.npy'%(images_processed+1))[0] count = 1 for i in xrange(images_processed+1, images_processed+image_group_count): if i > image_count: break i1 = load_img_arr('work/form1.%d.npy'%i)[0] i2 = load_img_arr('work/form2.%d.npy'%i)[0] h, w, d = len(block1), len(block1[0]), len(block1[0][0]) new_block_x = (block1.size + i1.size) / thread_x if (block1.size + i1.size) % thread_x: new_block_x += 1 new_block_y = block_y if new_block_x > GPU_ATTRIBUTES['MAX_GRID_DIM_X']: new_block_y += 1 if new_block_y > GPU_ATTRIBUTES['MAX_GRID_DIM_Y']: raise Exception('Grid getting too big') block1 = numpy.concatenate((block1,i1), axis=1) block2 = numpy.concatenate((block2,i2), axis=1) block_y = new_block_y else: block1 = numpy.concatenate((block1,i1), axis=0) block2 = numpy.concatenate((block2,i2), axis=0) block_x = new_block_x count += 1 grid_size = (block_x, block_y) print grid_size save_image_arr(block1, mode1, 'grid_out.%d.png' % images_processed) images_processed += image_group_count
#!/bin/python import sys import numpy n = int(raw_input().strip()) unsorted = [] unsorted_i = 0 final = [] for unsorted_i in xrange(n): unsorted_t = str(raw_input().strip()) unsorted.append(unsorted_t) max = numpy.Array(unsorted) print sorted(max) # for i in range(n): # for j in range(n-i-1): # if long(unsorted[j])>long(unsorted[j+1]): # t=unsorted[j] # unsorted[j]=unsorted[j+1] # unsorted[j+1]=t # # for i in unsorted: # print i
56: >>> b[2] = AFC_east 57: >>> b ['spam', 2.0, ['New England Patriots', 'Buffalo Bills', 'New York Giants', 'New York Jets'], 10] 58: >>> len(b) 4 59: >>> a = [1, 2, 3] 60: >>> b = [4, 5, 6] 61: >>> c = a + b 62: >>> c [1, 2, 3, 4, 5, 6] 63: >>> import numpy as np 64: >>> a = np.Arry([1, 2, 3]) 65: >>> a = np.Array([1, 2, 3]) 66: >>> [0] * 4 [0, 0, 0, 0] 67: >>> ['Tom Brady', 'Bill Belichick']*3 ['Tom Brady', 'Bill Belichick', 'Tom Brady', 'Bill Belichick', 'Tom Brady', 'Bill Belichick'] 68: >>> t = ['a', 'b', 'c', 'd', 'e', 'f'] 69: >>> t[1:2] ['b'] 70: >>> t[1:3] ['b', 'c'] 71: >>> t[0:5]
d =[array([10, 1, 7, 3]), array([ 0, 14, 12, 13]), array([ 3, 10, 7, 8]), array([7, 5]), array([ 5, 12, 3]), array([14, 8, 10])] d =pd.Array([10, 1, 7, 3], [ 0, 14, 12, 13], [ 3, 10, 7, 8], [7, 5], [ 5, 12, 3], [14, 8, 10]) import numpy as np d =np.Array([10, 1, 7, 3], [ 0, 14, 12, 13], [ 3, 10, 7, 8], [7, 5], [ 5, 12, 3], [14, 8, 10]) dir(np) dir(np.array) d =np.array([10, 1, 7, 3], [ 0, 14, 12, 13], [ 3, 10, 7, 8], [7, 5], [ 5, 12, 3], [14, 8, 10]) d =np.array([[10, 1, 7, 3], [ 0, 14, 12, 13], [ 3, 10, 7, 8], [7, 5], [ 5, 12, 3],
import numpy as np mynumber = 65 myList = [67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113] myArray = np.Array(myList)