code: def _softdtw_func(Z, X, weights, barycenter, gamma):
      # Compute objective value and grad at Z.
  
      Z = Z.reshape(barycenter.shape)
      G = numpy.zeros_like(Z)
      obj = 0
  
      for i in range(len(X)):
          D = SquaredEuclidean(Z, X[i])
          sdtw = SoftDTW(D, gamma=gamma)
          value = sdtw.compute()
          E = sdtw.grad()
          G_tmp = D.jacobian_product(E)
          G += weights[i] * G_tmp
          obj += weights[i] * value
  
      return obj, G.ravel()
  
file_path: tslearn/tslearn/barycenters/softdtw.py
imports: import numpy
  from scipy.optimize import minimize
  from tslearn.utils import to_time_series_dataset, check_equal_size, to_time_series
  from tslearn.preprocessing import TimeSeriesResampler
  from tslearn.metrics import SquaredEuclidean, SoftDTW
  from .utils import _set_weights
  from .euclidean import euclidean_barycenter
label_desc: Use image node_id 1 for calling a global function with example usage: _softdtw_func(Z, X, weights, barycenter, gamma) and returns: obj,  G