本文整理匯總了Python中OCO_Matrix.OCO_Matrix.data[:,column_idx]方法的典型用法代碼示例。如果您正苦於以下問題:Python OCO_Matrix.data[:,column_idx]方法的具體用法?Python OCO_Matrix.data[:,column_idx]怎麽用?Python OCO_Matrix.data[:,column_idx]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OCO_Matrix.OCO_Matrix
的用法示例。
在下文中一共展示了OCO_Matrix.data[:,column_idx]方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Process_File
# 需要導入模塊: from OCO_Matrix import OCO_Matrix [as 別名]
# 或者: from OCO_Matrix.OCO_Matrix import data[:,column_idx] [as 別名]
def Process_File(source, destination, fileKeywords, moduleSections, valuesDict, mapDict):
logger = logging.getLogger(os.path.basename(__file__))
# Load existing file
matrix_obj = OCO_Matrix(source)
for realizeSect in moduleSections:
# Add ability to specify cols individually or using a * to goto end
covariance = Apply_Template(realizeSect.Get_Keyword_Value('covariance'), valuesDict, mapDict=mapDict)
column = Apply_Template(realizeSect.Get_Keyword_Value('column'), valuesDict, mapDict=mapDict)
if type(column) is ListType:
raise TypeError('Only one column can be modified per file')
if covariance == None or len(covariance) == 0:
raise IOError('covariance file is not specified')
if not os.path.exists(covariance):
raise IOError('covariance file does not exist: %s' % covariance)
cov_obj = OCO_Matrix(covariance)
rand_factors = [ random.normalvariate(0,1) for i in range(matrix_obj.dims[0]) ]
(eigen_val, eigen_vec) = linalg.eigh(cov_obj.data)
try:
column_idx = int(column)
except:
if column == None:
raise IOError('column named not defined for source file: %s' % (source))
elif not column.lower() in matrix_obj.labels_lower:
raise IOError('column named %s not found in source file: %s' % (column, source))
column_idx = matrix_obj.labels_lower.index(column.lower())
update_vals = dot(eigen_vec.transpose(), (rand_factors* sqrt(eigen_val)))
matrix_obj.data[:, column_idx] = matrix_obj.data[:, column_idx] + update_vals
matrix_obj.write(destination)
示例2: write_spectra_files
# 需要導入模塊: from OCO_Matrix import OCO_Matrix [as 別名]
# 或者: from OCO_Matrix.OCO_Matrix import data[:,column_idx] [as 別名]
def write_spectra_files(output_dir, ids, data):
for curr_id, curr_data in zip(ids, data):
out_filename = '%s/%s.dat' % (output_dir, curr_id)
used_data = []
out_obj = OCO_Matrix()
out_obj.labels = FILE_LABELS
out_obj.units = FILE_UNITS
out_obj.file_id = FILE_ID_TMPL % (curr_id)
out_obj.data = numpy.zeros((curr_data['Num_Points'], len(FILE_LABELS)), dtype=float)
used_data.append('Num_Points')
for column_idx, column_name in enumerate(FILE_LABELS):
if curr_data.has_key(column_name):
out_obj.data[:, column_idx] = curr_data[column_name]
used_data.append(column_name)
header_dict = copy.copy(curr_data)
header_dict.update(HEADER_FILL_VALUES)
for data_name, data_values in header_dict.items():
if data_name in used_data:
continue
out_name = translate_header_name(data_name)
try:
if len(data_values.shape) == 0:
out_obj.header[out_name] = str(data_values)
else:
out_obj.header[out_name] = ' '.join([ str(item) for item in iter(data_values)])
except:
try:
out_obj.header[out_name] = str(data_values)
except:
print >>sys.stderr, 'Barfed on parsing %s with values: %s for header of file %s' % (data_name, data_values, out_filename)
print 'Writing: %s' % out_filename
out_obj.write(out_filename)