tf.segment_mean
时间: 2023-02-15 11:36:51 浏览: 58
tf.segment_mean 是 TensorFlow 中的一个函数,它可以计算张量的分段平均值。
输入参数:
- data:一个张量,表示输入数据。
- segment_ids:一个张量,它为每个数据元素提供了所属的分段编号。
- num_segments:一个整数,表示分段的总数。
输出:
- 一个张量,表示分段平均值。
例如,假设我们有一个张量 data,它的值如下:
[1, 2, 3, 4, 5, 6, 7, 8]
同时,我们有一个张量 segment_ids,它的值如下:
[0, 0, 0, 1, 1, 2, 2, 2]
这意味着第 1、2、3 个数据元素属于第 1 个分段,第 4、5 个数据元素属于第 2 个分段,第 6、7、8 个数据元素属于第 3 个分段。
如果我们将 num_segments 设为 3,则调用 tf.segment_mean(data, segment_ids, num_segments) 将返回一个新的张量,它的值为:
[2, 5, 7]
这意味着第 1 个分段的平均值为 2(= (1 + 2 + 3) / 3),第 2 个分段的平均值为 5(= (4 + 5) / 2),第 3 个分段的平均值为 7(= (6 + 7 + 8) / 3)。
相关问题
select tpi.id, sd.dept_id, sd.dept_name, tpi.year, tpi.project_name, tpi.construction_company, tpc.company_name as constructionCompanyName, (select sdd.dict_label from sys_dict_data sdd where sdd.dict_type = 'contract_segment' and sdd.dict_value = tpi.contract_segment) contractSegmentName, tpi.is_section from t_project_info tpi left join t_participating_company tpc on tpi.construction_company = tpc.id left join sys_dept sd on tpi.dept_id = sd.dept_id where tpi.del_flag = 0 and tpi.year = Date_format(now(),'%Y') and tpi.is_section = 0 and tpi.id not in(select group_concat(tci.project_id) from t_contract_info tci where tci.del_flag = 0 and tci.project_id != '');子查询语句和手动填的一致,结果却不一样
如果子查询语句和手动填的一致,但结果却不一样,可能是因为使用了 GROUP_CONCAT 函数来返回子查询结果中多个项目ID的字符串,而 NOT IN 语句中只能比较单个值,不能直接比较字符串。因此,你需要使用 INSTR 函数来判断子查询结果中是否包含指定的项目ID。例如:
SELECT tpi.id, sd.dept_id, sd.dept_name, tpi.year, tpi.project_name, tpi.construction_company, tpc.company_name as constructionCompanyName, (SELECT sdd.dict_label FROM sys_dict_data sdd WHERE sdd.dict_type = 'contract_segment' AND sdd.dict_value = tpi.contract_segment) contractSegmentName, tpi.is_section
FROM t_project_info tpi
LEFT JOIN t_participating_company tpc ON tpi.construction_company = tpc.id
LEFT JOIN sys_dept sd ON tpi.dept_id = sd.dept_id
WHERE tpi.del_flag = 0 AND tpi.year = DATE_FORMAT(NOW(), '%Y') AND tpi.is_section = 0 AND NOT EXISTS (
SELECT 1
FROM t_contract_info tci
WHERE tci.del_flag = 0 AND tci.project_id != '' AND INSTR(CONCAT(',', tci.project_id, ','), CONCAT(',', tpi.id, ','))
)
这里使用了 CONCAT 函数将子查询结果中多个项目ID拼接成一个字符串,然后使用 INSTR 函数来判断是否包含指定的项目ID。注意,这里在子查询中也使用了 NOT IN,但是为了避免子查询结果中包含 NULL 值导致 NOT IN 失效,使用了 NOT EXISTS 来避免这个问题。
帮我把这段SQL从(+)写法修改为left join写法: SELECT temp.segment8, aia.* FROM ap_invoices_all aia, (SELECT aid.invoice_id, gcc.segment8, row_number() over(PARTITION BY aid.invoice_id, gcc.segment8 ORDER BY aid.invoice_id) row_num FROM ap_invoice_distributions_all aid, gl_code_combinations gcc WHERE gcc.code_combination_id = aid.dist_code_combination_id) temp WHERE aia.invoice_num = 'CBS202305041001' AND aia.invoice_id = temp.invoice_id(+) AND temp.row_num(+) = 1
当将(+)写法修改为left join写法时,我们需要将原始查询中的两个关联条件进行修改。下面是修改后的SQL查询:
SELECT temp.segment8, aia.*
FROM ap_invoices_all aia
LEFT JOIN
(SELECT aid.invoice_id,
gcc.segment8,
row_number() over(PARTITION BY aid.invoice_id, gcc.segment8 ORDER BY aid.invoice_id) row_num
FROM ap_invoice_distributions_all aid
INNER JOIN gl_code_combinations gcc ON gcc.code_combination_id = aid.dist_code_combination_id) temp
ON aia.invoice_id = temp.invoice_id AND temp.row_num = 1
WHERE aia.invoice_num = 'CBS202305041001'