title: TypeError: can't multiply sequence by non-int of type 'float' for Python
body: <p>I facing an error:</p>
  <pre><code>TypeError: can't multiply sequence by non-int of type 'float'
  </code></pre>
  <p>Not sure where is the error...headhache</p>
  <pre><code>inp_df = final_df.drop(final_df.columns[[4]], axis=1)
  out_df = final_df.drop(final_df.columns[[0,1,2,3]], axis=1)
  #
  scaler = StandardScaler()
  inp_df = scaler.fit_transform(inp_df)
  #
  X_train, X_test, y_train, y_test = train_test_split(inp_df, out_df, test_size=0.2, random_state=42)
  
  inp_df = final_df.drop(final_df.columns[[4]], axis=1)
  out_df = final_df.drop(final_df.columns[[0,1,2,3]], axis=1)
  #
  scaler = StandardScaler()
  inp_df = scaler.fit_transform(inp_df)
  #
  X_train, X_test, y_train, y_test = train_test_split(inp_df, out_df, test_size=0.2, random_state=42)
  
  print('Input Shape', (X_tr_arr.shape))
  print('Output Shape', X_test.shape)
  
  def weightInitialization(n_features):
      w = np.zeros((1,n_features))
      b = 0
      return w,b
  
  def sigmoid_activation(result):
      final_result = 1/(1+np.exp(-result))
      return final_result
  
  
  def model_optimize(w, b, X, Y):
      m = X.shape[0]
      
      #Prediction
      final_result = sigmoid_activation(np.dot(w,X.T)+b)
      Y_T = Y.T
      cost = (-1/m)*(np.sum((Y_T*np.log(final_result)) + ((1-Y_T)*(np.log(1-final_result)))))
      #
      
      #Gradient calculation
      dw = (1/m)*(np.dot(X.T, (final_result-Y.T).T))
      db = (1/m)*(np.sum(final_result-Y.T))
      
      grads = {&quot;dw&quot;: dw, &quot;db&quot;: db}
      
      return grads, cost
  
  def model_predict(w, b, X, Y, learning_rate, no_iterations):
      costs = []
      for i in range(no_iterations):
          #
          grads, cost = model_optimize(w,b,X,Y)
          #
          dw = grads[&quot;dw&quot;]
          db = grads[&quot;db&quot;]
          #weight update
          w = w - (learning_rate * (dw.T))
          b = b - (learning_rate * db)
          #
          
          if (i % 100 == 0):
              costs.append(cost)
              #print(&quot;Cost after %i iteration is %f&quot; %(i, cost))
      
      #final parameters
      coeff = {&quot;w&quot;: w, &quot;b&quot;: b}
      gradient = {&quot;dw&quot;: dw, &quot;db&quot;: db}
      
      return coeff, gradient, costs
  
  def predict(final_pred, m):
      y_pred = np.zeros((1,m))
      for i in range(final_pred.shape[1]):
          if final_pred[0][i] &gt; 0.5:
              y_pred[0][i] = 1
      return y_pred
  
  
  
  
  
  
  
  
  
  #Get number of features
  n_features = X_tr_arr.shape[1]
  print('Number of Features', n_features)
  w, b = weightInitialization(n_features)
  #Gradient Descent
  coeff, gradient, costs = model_predict(w, b, X_tr_arr, y_tr_arr, learning_rate=0.0001,no_iterations=4500)
  #Final prediction
  w = coeff[&quot;w&quot;]
  b = coeff[&quot;b&quot;]
  print('Optimized weights', w)
  print('Optimized intercept',b)
  #
  final_train_pred = sigmoid_activation(np.dot(w,X_tr_arr.T)+b)
  final_test_pred = sigmoid_activation(np.dot(w,X_ts_arr.T)+b)
  #
  m_tr =  X_tr_arr.shape[0]
  m_ts =  X_ts_arr.shape[0]
  #
  y_tr_pred = predict(final_train_pred, m_tr)
  print('Training Accuracy',accuracy_score(y_tr_pred.T, y_tr_arr))
  #
  y_ts_pred = predict(final_test_pred, m_ts)
  print('Test Accuracy',accuracy_score(y_ts_pred.T, y_ts_arr))
  </code></pre>
  <p>I am using python notebook</p>
  <p>('Number of Features', 4L)</p>
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-110-2e390b463717&gt; in &lt;module&gt;()
        4 w, b = weightInitialization(n_features)
        5 #Gradient Descent
  ----&gt; 6 coeff, gradient, costs = model_predict(w, b, X_tr_arr, y_tr_arr, learning_rate=0.0001,no_iterations=4500)
        7 #Final prediction
        8 w = coeff[&quot;w&quot;]
  
  &lt;ipython-input-107-f28af5fdf927&gt; in model_predict(w, b, X, Y, learning_rate, no_iterations)
        3     for i in range(no_iterations):
        4         #
  ----&gt; 5         grads, cost = model_optimize(w,b,X,Y)
        6         #
        7         dw = grads[&quot;dw&quot;]
  
  &lt;ipython-input-106-d37a364dc23d&gt; in model_optimize(w, b, X, Y)
        5     final_result = sigmoid_activation(np.dot(w,X.T)+b)
        6     Y_T = Y.T
  ----&gt; 7     cost = (-1/m)*(np.sum((Y_T*np.log(final_result)) + ((1-Y_T)*(np.log(1-final_result)))))
        8     #
        9 
  
  TypeError: can't multiply sequence by non-int of type 'float'
  </code></pre>