code: def create_ratings_matrix(
      df: pd.DataFrame,
      user_col: str = "user_id",
      item_col: str = "item_id",
      ratings_col: str = "rating",
      sparse: bool = False,
  ) -> (coo_matrix, np.array):
      """
      Helper function to convert a Pandas DataFrame to 2-dimensional matrix.
  
      Parameters
      ----------
      df: pd.DataFrame
          Dataframe with columns for user IDs, item IDs, and ratings
      user_col: str
          Column name for the user IDs
      item_col: str
          Column name for the item IDs
      ratings_col: str
          Column name for the ratings column
      sparse: bool
          Whether to return data as a sparse ``coo_matrix`` (True) or np.array (False)
  
      Returns
      -------
      ratings_matrix: np.array or scipy.sparse.coo_matrix, 2-d
          Data with users as rows, items as columns, and ratings as values
  
      """
      if sparse:
          ratings_matrix = _create_sparse_ratings_matrix_helper(
              users=df[user_col],
              items=df[item_col],
              ratings=df[ratings_col],
          )
      else:
          if df[user_col].min() != 0 or df[item_col].min() != 0:
              raise ValueError(
                  "Minimum values of ``df[user_col]`` and ``df[item_col]`` must both be 0."
              )
  
          ratings_df = df.pivot(
              index=user_col, columns=item_col, values=ratings_col
          ).fillna(0)
          ratings_matrix = ratings_df.to_numpy()
  
      return ratings_matrix
  
imports: from datetime import datetime
  import inspect
  from pathlib import Path
  import re
  import time
  from typing import Any, Dict, Iterable, List, Optional, Union
  import docstring_parser
  import numpy
  import pandas
  import pytorch_lightning
  from scipy.sparse import coo_matrix
  import torch
  from collie.interactions import Interactions
label_desc: Use image node_id 2 for calling a global function with example usage: create_ratings_matrix(df, user_col, item_col, ratings_col, sparse) and returns: ratings_matrix