Teradata Package for Python Function Reference | 20.00 - array_sub - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Package for Python
Release Number
20.00.00.11
Published
August 2026
ft:locale
en-US
ft:lastEdition
2026-08-13
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.array_sub = array_sub(self, other, lower_bound=None, upper_bound=None)
DESCRIPTION:
    Subtract another array or scalar value from the elements of the array
    element-wise and return the resultant array.
 
PARAMETERS:
    other:
        Required Argument.
        Specifies the array or Python literal value to subtract.
        Note:
            * Value specified in "other" must be of the same type as the array to subtract.
        Types: ColumnExpression OR Python literal
 
    lower_bound:
        Optional Argument.
        Specifies the starting index for subtraction (inclusive).
        Note:
            * If specified, both "lower_bound" and "upper_bound" arguments must be provided.
        Types: int
 
    upper_bound:
        Optional Argument.
        Specifies the ending index for subtraction (inclusive).
        Note:
            * If specified, both "lower_bound" and "upper_bound" arguments must be provided.
        Types: int
 
RETURNS:
    ColumnExpression
 
EXAMPLES:
    >>> from teradataml import *
    >>> load_example_data("array", "array_table")
 
    # Create a DataFrame on 'array_table'.
    >>> df = DataFrame("array_table")
    >>> df
                     arr1                   arr2                        arr3
    id                                                                      
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','lm')
 
    # Example 1: Subtract corresponding elements of array column 'arr1' from 'arr2'.
    >>> res = df.assign(sub_res = df.arr2.array_sub(df.arr1))
    >>> res
                     arr1                   arr2                        arr3                   sub_res
    id                                                                                                
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')        (13,180,185,0,-29)
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')  (-150,NULL,NULL,202,-31)
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')       (-122,25,60,45,-29)
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')        (13,-91,124,0,-31)
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')       (13,0,-180,158,-29)
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','ab')    (12,NULL,NULL,136,-30)
    >>>
 
    # Example 2: Subtract a scalar value 5 from all elements in array column 'arr1'.
    >>> res = df.assign(sub_res = df.arr1.array_sub(5))
    >>> res
                    arr1                   arr2                        arr3            sub_res
    id                                                                                         
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')    (5,15,25,35,45)
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')  (175,23,33,43,53)
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')  (145,20,30,40,50)
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')  (11,256,31,41,51)
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')   (7,17,315,37,47)
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','ab')    (9,19,29,39,49)
 
    # Example 3: Subtract a scalar value 10 from the elements present in first position to third position
    #            in the array column 'arr1'.
    >>> res = df.assign(sub_res = df.arr1.array_sub(10, lower_bound=1, upper_bound=3))
    >>> res
                     arr1                   arr2                        arr3                sub_res
    id                                                                                             
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')    (0,10,20,NULL,NULL)
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')  (170,18,28,NULL,NULL)
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')  (140,15,25,NULL,NULL)
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')   (6,251,26,NULL,NULL)
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')   (2,12,310,NULL,NULL)
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','ab')    (4,14,24,NULL,NULL)
 
    # Example 4: Subtract the elements present in second position to fourth position in the array column
    #            'arr1' from the corresponding elements in array column 'arr2'.
    >>> res = df.assign(sub_res = df.arr2.array_sub(df.arr1, lower_bound=2, upper_bound=4))
    >>> res
                     arr1                   arr2                        arr3                    sub_res
    id                                                                                                 
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')      (NULL,180,185,0,NULL)
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')  (NULL,NULL,NULL,202,NULL)
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')       (NULL,25,60,45,NULL)
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')      (NULL,-91,124,0,NULL)
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')     (NULL,0,-180,158,NULL)
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','ab')  (NULL,NULL,NULL,136,NULL)