本文整理汇总了Python中OCO_Matrix.OCO_Matrix.data[rowIdx][colIdx]方法的典型用法代码示例。如果您正苦于以下问题:Python OCO_Matrix.data[rowIdx][colIdx]方法的具体用法?Python OCO_Matrix.data[rowIdx][colIdx]怎么用?Python OCO_Matrix.data[rowIdx][colIdx]使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCO_Matrix.OCO_Matrix
的用法示例。
在下文中一共展示了OCO_Matrix.data[rowIdx][colIdx]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: offset_column
# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data[rowIdx][colIdx] [as 别名]
def offset_column(input_file, output_file, columns, offset, method, pressure_range=None):
# Load existing file
matrix_obj = OCO_Matrix(input_file)
# Add ability to specify cols individually or using a * to goto end
cols = index_range_list(columns)
if offset.isdigit():
offset = float(offset)
else:
offset = eval(offset)
if pressure_range != None:
pres_col = matrix_obj.labels_lower.index("pressure")
pres_range_arr = pressure_range.split(',')
pres_val_beg = float(pres_range_arr[0])
pres_val_end = float(pres_range_arr[1])
pres_idx_beg = 0
pres_idx_end = matrix_obj.dims[0]
pres_column = []
[ pres_column.append(float(val[pres_col])) for val in matrix_obj.data ]
pres_idx_curr = 0
beg_found = False
for pres_val in pres_column:
if pres_val >= pres_val_beg and not beg_found:
pres_idx_beg = pres_idx_curr
beg_found = True
if pres_val <= pres_val_end:
pres_idx_end = pres_idx_curr + 1
pres_idx_curr += 1
target_rows = range(pres_idx_beg, pres_idx_end)
else:
target_rows = range(matrix_obj.dims[0])
for rowIdx in target_rows:
for colIdx in cols:
#print 'old_val[%d][%d] = %f' % (rowIdx, colIdx, matrix_obj.data[rowIdx][colIdx])
if method == '/':
matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] / offset
elif method == '-':
matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] - offset
elif method == '*':
matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] * offset
else:
matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] + offset
#print 'new_val[%d][%d] = %f' % (rowIdx, colIdx, matrix_obj.data[rowIdx][colIdx])
matrix_obj.write(output_file)
示例2: random_column
# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data[rowIdx][colIdx] [as 别名]
def random_column(input_file, output_file, columns, mean, std_dev):
# Load existing file
matrix_obj = OCO_Matrix(input_file)
# Add ability to specify cols individually or using a * to goto end
cols = index_range_list(columns)
mean = float(mean)
std_dev = float(std_dev)
target_rows = range(matrix_obj.dims[0])
for rowIdx in target_rows:
for colIdx in cols:
matrix_obj.data[rowIdx][colIdx] = random.gauss(mean, std_dev)
matrix_obj.write(output_file)