code: def scalar_op_helper(node, op_name, **kwargs):
      """Helper function for scalar arithmetic operations"""
      from onnx import numpy_helper
  
      name, input_nodes, attrs = get_inputs(node, kwargs)
      input_dtypes = get_input_dtypes(node, kwargs)
  
      dtype = input_dtypes[0]
      dtype_t = onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[dtype]
  
      scalar_value = np.array([attrs.get("scalar", 1)], dtype=dtype)
      initializer = kwargs["initializer"]
      flag = True
      # If the input value is in initializer, just multiply with scalar input
      # and create a new initializer
      for i in initializer:
          if i.name == input_nodes[0]:
              if op_name == "Mul":
                  new_initializer = (
                      numpy_helper.to_array(i) * scalar_value[0]
                  )
              elif op_name == "Sub":
                  if name.startswith("_rminusscalar"):
                      new_initializer = scalar_value[
                          0
                      ] - numpy_helper.to_array(i)
                  else:
                      new_initializer = (
                          numpy_helper.to_array(i) - scalar_value[0]
                      )
              elif op_name == "Add":
                  new_initializer = (
                      numpy_helper.to_array(i) + scalar_value[0]
                  )
              elif op_name == "Div":
                  if name.startswith("_rdivscalar"):
                      new_initializer = scalar_value[
                          0
                      ] / numpy_helper.to_array(i)
                  else:
                      new_initializer = (
                          numpy_helper.to_array(i) / scalar_value[0]
                      )
              elif op_name == "Pow":
                  new_initializer = (
                      numpy_helper.to_array(i) ** scalar_value[0]
                  )
              flag = False
              break
  
      # else create a new tensor of the scalar value, add it in initializer
      if flag is True:
          dims = np.shape(scalar_value)
  
          scalar_op_name = "scalar_op" + str(kwargs["idx"])
          tensor_node = onnx.helper.make_tensor_value_info(
              scalar_op_name, dtype_t, dims
          )
  
          initializer.append(
              onnx.helper.make_tensor(
                  name=scalar_op_name,
                  data_type=dtype_t,
                  dims=dims,
                  vals=scalar_value,
                  raw=False,
              )
          )
  
          mul_node = onnx.helper.make_node(
              op_name,
              [input_nodes[0], scalar_op_name],
              [name],
              name=name,
          )
  
          return [tensor_node, mul_node]
      else:
          dtype_t = onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[
              new_initializer.dtype
          ]
          dims = np.shape(new_initializer)
  
          tensor_node = onnx.helper.make_tensor_value_info(
              name, dtype_t, dims
          )
  
          initializer.append(
              onnx.helper.make_tensor(
                  name=name,
                  data_type=dtype_t,
                  dims=dims,
                  vals=new_initializer.flatten(),
                  raw=False,
              )
          )
          return [tensor_node]
  
      return create_basic_op_node("Shape", node, kwargs)
  
imports: import re
  import logging
  import numpy
  from .._export_onnx import MXNetGraph
label_desc: Use image node_id 12 for calling a global function with example usage: scalar_op_helper(node, op_name) and returns: create_basic_op_node, list, list