当前位置: 首页>>代码示例>>Python>>正文


Python numpy.array_repr函数代码示例

本文整理汇总了Python中numpy.array_repr函数的典型用法代码示例。如果您正苦于以下问题:Python array_repr函数的具体用法?Python array_repr怎么用?Python array_repr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了array_repr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_ppc_file

def write_ppc_file(fname):
    """Save PYPOWER file. 
    """
    
    filename = fname
        
    base = os.path.basename(fname)
    casename = os.path.splitext(base)[0]
    
    outfile = open(fname, 'w', newline='')
    
    outfile.write('from numpy import array\n\n')
    
    outfile.write('def ' + casename + '():\n') 
    outfile.write('\tppc = {"version": ''2''}\n')
    outfile.write('\tppc["baseMVA"] = 100.0\n')
   
    outfile.write('\tppc["bus"] = ')
    outfile.write(np.array_repr(ppc["bus"]))
    outfile.write('\n\n')
     
    outfile.write('\tppc["gen"] = ')
    outfile.write(np.array_repr(ppc["gen"]))
    outfile.write('\n\n')
    
    outfile.write('\tppc["branch"] = ')
    outfile.write(np.array_repr(ppc["branch"]))
    outfile.write('\n\n')
    
    outfile.write('\treturn ppc')
    outfile.close()
    
    return True
开发者ID:susantoj,项目名称:PYPOWER-Gui,代码行数:33,代码来源:gui_globals.py

示例2: __repr__

 def __repr__(self):
   # if numpy.all(self == 0):
   #   # Bin-only output
   #   return "{}(bins={})".format(type(self).__name__, numpy.array_repr(self._bins))
   # else:
   if self.ndim == 1:
     return "{}({}, data={})".format(type(self).__name__,
       numpy.array_repr(self._bins)[len("array("):-1], 
       numpy.array_repr(self)[len(type(self).__name__)+1:-1])
   else:
     return "{}(({}), data={})".format(type(self).__name__,
       ",".join([numpy.array_repr(x)[6:-1] for x in self._bins]), 
       numpy.array_repr(self)[len(type(self).__name__)+1:-1])
开发者ID:ndevenish,项目名称:simplehistogram,代码行数:13,代码来源:hists.py

示例3: test

def test():
    from sklearn.metrics import mean_squared_error
    import Surrogates.DataExtraction.pcs_parser as pcs_parser
    sp = pcs_parser.read(file("/home/eggenspk/Surrogates/Data_extraction/Experiments2014/hpnnet/smac_2_06_01-dev/nips2011.pcs"))
    # Read data from csv
    header, data = read_csv("/home/eggenspk/Surrogates/Data_extraction/hpnnet_nocv_convex_all/hpnnet_nocv_convex_all_fastrf_results.csv",
                            has_header=True, num_header_rows=3)
    para_header = header[0][:-2]
    type_header = header[1]
    cond_header = header[2]
    #print data.shape
    checkpoint = hash(numpy.array_repr(data))
    assert checkpoint == 246450380584980815

    model = GaussianProcess(sp=sp, encode=False, rng=1, debug=True)
    x_train_data = data[:100, :-2]
    y_train_data = data[:100, -1]
    x_test_data = data[100:, :-2]
    y_test_data = data[100:, -1]

    model.train(x=x_train_data, y=y_train_data, param_names=para_header)

    y = model.predict(x=x_train_data[1, :])
    print "Is: %100.70f, Should: %f" % (y, y_train_data[1])
    assert y[0] == 0.470745153514900149804844886602950282394886016845703125

    print "Predict whole data"
    y_whole = model.predict(x=x_test_data)
    mse = mean_squared_error(y_true=y_test_data, y_pred=y_whole)
    print "MSE: %100.70f" % mse
    assert mse == 0.006257598609004190459703664828339242376387119293212890625

    print "Soweit so gut"

    # Try the same with encoded features
    model = GaussianProcess(sp=sp, encode=True, rng=1, debug=True)
    #print data[:10, :-2]
    model.train(x=x_train_data, y=y_train_data, param_names=para_header)

    y = model.predict(x=x_train_data[1, :])
    print "Is: %100.70f, Should: %f" % (y, y_train_data[1])
    assert y[0] == 0.464671665294324409689608046392095275223255157470703125

    print "Predict whole data"
    y_whole = model.predict(x=x_test_data)
    mse = mean_squared_error(y_true=y_test_data, y_pred=y_whole)
    print "MSE: %100.70f" % mse
    assert mse == 0.00919265128042330570412588031103950925171375274658203125

    assert hash(numpy.array_repr(data)) == checkpoint
开发者ID:KEggensperger,项目名称:SurrogateBenchmarks,代码行数:50,代码来源:GaussianProcess.py

示例4: myf

def myf(x):
	header = 'MaxStepX, TorsoWy, TorsoWx, StepHeight, Stiffness, MaxStepTheta, MaxStepY, MaxStepFrequency'
	print header
	print np.array_repr(x[0]).replace('\n', '').replace('\t', '')
	speed = input('Input 1/average_speed = ')
	output = np.array(float(speed))

	with open("data_new.py",'a') as f:
		np.savetxt(f, x, delimiter=",")
	# 	for item in x:
	# 		f.write("%s\n" % str(np.array_repr(item).replace('\n', '').replace('\t', '')))
	with open("readings_new.py",'a') as f:
		f.write("%s\n" % str(output))
	return output
开发者ID:victorbergelin,项目名称:bayesianglobaloptimization,代码行数:14,代码来源:BOnao.py

示例5: test

def test():
    from sklearn.metrics import mean_squared_error
    import Surrogates.DataExtraction.pcs_parser as pcs_parser
    sp = pcs_parser.read(file("/home/eggenspk/Surrogates/Data_extraction/Experiments2014/hpnnet/smac_2_06_01-dev/nips2011.pcs"))
    # Read data from csv
    header, data = read_csv("/home/eggenspk/Surrogates/Data_extraction/hpnnet_nocv_convex_all/hpnnet_nocv_convex_all_fastrf_results.csv",
                            has_header=True, num_header_rows=3)
    para_header = header[0][:-2]
    type_header = header[1]
    cond_header = header[2]
    #print data.shape
    checkpoint = hash(numpy.array_repr(data))
    assert checkpoint == 246450380584980815

    model = GradientBoosting(sp=sp, encode=False, debug=True)
    x_train_data = data[:1000, :-2]
    y_train_data = data[:1000, -1]
    x_test_data = data[1000:, :-2]
    y_test_data = data[1000:, -1]

    model.train(x=x_train_data, y=y_train_data, param_names=para_header, rng=1)

    y = model.predict(x=x_train_data[1, :])
    print "Is: %100.70f, Should: %f" % (y, y_train_data[1])
    assert y[0] == 0.45366000254662230961599789225147105753421783447265625

    print "Predict whole data"
    y_whole = model.predict(x=x_test_data)
    mse = mean_squared_error(y_true=y_test_data, y_pred=y_whole)
    print "MSE: %100.70f" % mse
    assert mse == 0.00188246958253847243396073007914992558653466403484344482421875

    print "Soweit so gut"

    # Try the same with encoded features
    model = GradientBoosting(sp=sp, encode=True, debug=True)
    #print data[:10, :-2]
    model.train(x=x_train_data, y=y_train_data, param_names=para_header, rng=1)

    y = model.predict(x=x_train_data[1, :])
    print "Is: %100.70f, Should: %f" % (y, y_train_data[1])
    assert y[0] == 0.460818965082699205648708584703854285180568695068359375

    print "Predict whole data"
    y_whole = model.predict(x=x_test_data)
    mse = mean_squared_error(y_true=y_test_data, y_pred=y_whole)
    print "MSE: %100.70f" % mse
    assert mse == 0.002064362783199560034963493393433964229188859462738037109375

    assert hash(numpy.array_repr(data)) == checkpoint
开发者ID:KEggensperger,项目名称:SurrogateBenchmarks,代码行数:50,代码来源:GradientBoosting.py

示例6: showProjectionDialog

    def showProjectionDialog(self):
        """Get and set OpenGL ModelView matrix and focus.
        Useful for setting two different instances to the exact same projection"""
        dlg = uic.loadUi("multilineinputdialog.ui")
        dlg.setWindowTitle("Get and set OpenGL ModelView matrix and focus")
        precision = 8  # use default precision
        MV_repr = np.array_repr(self.MV, precision=precision)
        focus_repr = np.array_repr(self.focus, precision=precision)
        txt = "self.MV = \\\n" "%s\n\n" "self.focus = %s" % (MV_repr, focus_repr)
        dlg.plainTextEdit.insertPlainText(txt)
        dlg.plainTextEdit.selectAll()
        if dlg.exec_():  # returns 1 if OK, 0 if Cancel
            txt = str(dlg.plainTextEdit.toPlainText())
            from numpy import array, float32  # required for exec()

            exec(txt)  # update self.MV and self.focus, with hopefully no maliciousness
开发者ID:yagui,项目名称:spyke,代码行数:16,代码来源:opengl_demo.py

示例7: setUp

 def setUp(self):
     self._sp = pcs_parser.read(file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "Testdata/nips2011.pcs")))
     # Read data from csv
     header, self._data = read_csv(os.path.join(os.path.dirname(os.path.realpath(__file__)), "Testdata/hpnnet_nocv_convex_all_fastrf_results.csv"),
                                   has_header=True, num_header_rows=3)
     self._para_header = header[0][:-2]
     self._checkpoint = hash(numpy.array_repr(self._data))
开发者ID:KEggensperger,项目名称:SurrogateBenchmarks,代码行数:7,代码来源:RandomForestTest.py

示例8: __init__

  def __init__(self,q,x,f,qdesc="q",xdesc="x",fdesc="f"):
    """
    q    ... 1D-array of shape (q.size)
    x    ... 2D-array of shape (q.size,x.size)
    f    ... 2D-array of shape (q.size,x.size)
    *desc... description string for q,x,f
    """
    
    self.f = np.asarray(f,dtype='float');
    self.x = np.asarray(x,dtype='float');
    self.q = np.asarray(q,dtype='float');
    self.fdesc = fdesc;
    self.xdesc = xdesc;
    self.qdesc = qdesc;

    # complete input data (if constant for different q)
    if (len(self.x.shape)==1):
      self.x=np.tile(self.x,(len(self.q),1));
    if (len(self.f.shape)==1):
      self.f=np.tile(self.f,(len(self.q),1));

    # test shape of input data
    if (self.q.shape[0] <> self.x.shape[0]) or \
       (self.x.shape    <> self.f.shape):
      raise ValueError("Invalid shape of arguments.");

    # test for double parameters
    if (np.unique(self.q).size < self.q.size):
      raise ValueError("Parameters are not unique: \n " + np.array_repr(np.sort(self.q)));
开发者ID:rhambach,项目名称:EELcalc,代码行数:29,代码来源:interspectus.py

示例9: write

    def write(self):
        outdict = {'model'            : self.model,
                   'data_out'         : {'q'       : json.dumps(self.q_vals_out),
                                         'i'       : json.dumps(self.i_vals_out),
                                         'units'   : 'A^-1'},
                   'run'              : {'command' : self.command,
                                         'date'    : str(datetime.date.today()),
                                         'time'    : str(datetime.time())},
                   'parameters_in'    : self.parameters_in}

        if self.dataset:
            outdict['dataset'] = {'q_in' : json.dumps(self.datain.q),
                                  'i_in' : json.dumps(self.datain.i)}
            
        if (self.fitsuccess and (self.command == 'fit')):
            outdict['fit'] = {'chi^2'          : self.chisqr,
                              'cov_x'          : np.array_repr(self.cov_x),
                              'parameters_out' : self.parameters}

        path, filename = os.path.split(self.outpath)
        if filename == '':
             filename = self.outfile
             
        if not os.path.exists(path):
            os.mkdir(path)

        if self.xml:
            self.write_cml(path, filename)

        else:
            f = open(os.path.join(path, filename), 'w')
            json.dump(outdict, f)
            f.close()
开发者ID:cameronneylon,项目名称:contrail,代码行数:33,代码来源:modelling.py

示例10: __repr__

    def __repr__(self):
        """representation a mdf_skeleton class data strucutre

        Returns:
        ------------
        string of mdf class ordered as below
        master_channel_name
            channel_name   description
            numpy_array    unit
        """
        output = 'file name : ' + self.fileName + '\n'
        for m in self.file_metadata.keys():
            output += m + ' : ' + str(self.file_metadata[m]) + '\n'
        output += '\nchannels listed by data groups:\n'
        for d in self.masterChannelList.keys():
            if d is not None:
                output += d + '\n'
            for c in self.masterChannelList[d]:
                output += '  ' + c + ' : '
                desc = self.getChannelDesc(c)
                if desc is not None:
                    output += str(desc)
                output += '\n    '
                data = self.getChannelData(c)
                if data.dtype.kind != 'V': # not byte, impossible to represent
                    output += array_repr(data, \
                        precision=3, suppress_small=True)
                unit = self.getChannelUnit(c)
                output += ' ' + unit + '\n'
        return output
开发者ID:freeyyc,项目名称:mdfreader,代码行数:30,代码来源:mdf.py

示例11: test_train

    def test_train(self):
        model = Surrogates.RegressionModels.RidgeRegression.RidgeRegression(sp=self._sp, encode=False, rng=1, debug=True)
        x_train_data = self._data[:1000, :-2]
        y_train_data = self._data[:1000, -1]
        x_test_data = self._data[1000:, :-2]
        y_test_data = self._data[1000:, -1]

        self.assertEqual(hash(numpy.array_repr(x_train_data)), -4233919799601849470)
        self.assertEqual(hash(numpy.array_repr(y_train_data)), -5203961977442829493)

        model.train(x=x_train_data, y=y_train_data, param_names=self._para_header)

        lower, upper = model._scale_info
        should_be_lower = [None, -29.6210089736, 0.201346561323, 0, -20.6929600285, 0, 0, 0, 4.60517018599, 0,
                           2.77258872224, 0, 0, 0.502038871605, -17.2269829469]
        should_be_upper = [None, -7.33342451433, 1.99996215592, 1, -6.92778489957, 2, 1, 1, 9.20883924585, 1,
                           6.9314718056, 3, 1, 0.998243871085, 4.72337617503]

        for idx in range(x_train_data.shape[1]):
            self.assertEqual(lower[idx], should_be_lower[idx])
            self.assertEqual(upper[idx], should_be_upper[idx])

        y = model.predict(x=x_train_data[1, :])
        print "Is: %100.70f, Should: %f" % (y, y_train_data[1])
        self.assertAlmostEqual(y[0], 0.337919078549359763741222195676527917385101318359375, msg=y[0])

        print "Predict whole data"
        y_whole = model.predict(x=x_test_data)
        mse = mean_squared_error(y_true=y_test_data, y_pred=y_whole)
        print "MSE: %100.70f" % mse
        self.assertAlmostEqual(mse, 0.009198484147153261625273756862)

        # Try the same with encoded features
        model = Surrogates.RegressionModels.RidgeRegression.RidgeRegression(sp=self._sp, encode=True, rng=1, debug=True)
        #print data[:10, :-2]
        model.train(x=x_train_data, y=y_train_data, param_names=self._para_header, rng=1)

        y = model.predict(x=self._data[1, :-2])
        print "Is: %100.70f, Should: %f" % (y, self._data[1, -2])
        self.assertAlmostEqual(y[0], 0.337619548171, msg="%f" % y[0])

        print "Predict whole data"
        y_whole = model.predict(x=x_test_data)
        mse = mean_squared_error(y_true=y_test_data, y_pred=y_whole)
        print "MSE: %100.70f" % mse
        self.assertAlmostEqual(mse, 0.0092026737874672301)
开发者ID:KEggensperger,项目名称:SurrogateBenchmarks,代码行数:46,代码来源:RidgeRegressionTest.py

示例12: __str__

 def __str__(self):
     """ prints compressed_data object content
     """
     output = 'Data: \n'
     output += array_repr(self.data[:],
                          precision=3,
                          suppress_small=True)
     output += '\n Compression level ' + str(self._compression_level) + '\n'
     return output
开发者ID:lepy,项目名称:mdfreader,代码行数:9,代码来源:mdf.py

示例13: _repr_footer

    def _repr_footer(self):
        levheader = "Levels (%d): " % len(self.levels)
        # TODO: should max_line_width respect a setting?
        levstring = np.array_repr(self.levels, max_line_width=60)
        indent = " " * (levstring.find("[") + len(levheader) + 1)
        lines = levstring.split("\n")
        levstring = "\n".join([lines[0]] + [indent + x.lstrip() for x in lines[1:]])

        namestr = "Name: %s, " % self.name if self.name is not None else ""
        return u("%s\n%sLength: %d" % (levheader + levstring, namestr, len(self)))
开发者ID:pombredanne,项目名称:pandas,代码行数:10,代码来源:categorical.py

示例14: __repr__

    def __repr__(self):
        temp = "Categorical: %s\n%s\n%s"
        values = np.asarray(self)
        levheader = "Levels (%d): " % len(self.levels)
        levstring = np.array_repr(self.levels, max_line_width=60)

        indent = " " * (levstring.find("[") + len(levheader) + 1)
        lines = levstring.split("\n")
        levstring = "\n".join([lines[0]] + [indent + x.lstrip() for x in lines[1:]])

        return temp % ("" if self.name is None else self.name, repr(values), levheader + levstring)
开发者ID:mattyhk,项目名称:basketball-django,代码行数:11,代码来源:categorical.py

示例15: __repr__

 def __repr__(self):
     output = 'file name : ' + self.fileName + '\n'
     for m in self.file_metadata.keys():
         output += m + ' : ' + str(self.file_metadata[m]) + '\n'
     output += '\nchannels listed by data groups:\n'
     for d in self.masterChannelList.keys():
         if d is not None:
             output += d + '\n'
         for c in self.masterChannelList[d]:
             output += '  ' + c + ' : ' + str(self[c]['description']) + '\n'
             output += '    ' + array_repr(self[c]['data'], precision=3, suppress_small=True) \
                 + ' ' + self[c]['unit'] + '\n'
     return output
开发者ID:sneusse,项目名称:mdfreader,代码行数:13,代码来源:mdf.py


注:本文中的numpy.array_repr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。