Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Finding the Sum of a Symmetrical Sub-List

import numpy as np

def symmetrical_sum (arr):
    l = len(arr)-1
    bool_arr = np.array([x==arr[l-i] for i,x in enumerate(arr)])
    idx_arr = np.where(bool_arr==True)[0]
    if len(idx_arr):
        res = arr[min(idx_arr):max(idx_arr)+1]
    else:
        res = []
    return (res, sum(res))
Comment

PREVIOUS NEXT
Code Example
Python :: bad resolution with df plot 
Python :: relation api profile does not exist django 
Python :: get maximum values in a column by a subgroup of a dataframe pandas 
Python :: How to change the height of an input in python tkinter 
Python :: actual python iterators 
Python :: torch.unsqueeze 
Python :: python move all txt files 
Python :: max sum slice python 1 - autopilot 
Python :: perceptron multicouche scratch python 
Python :: Walrus operator in list comprehensions [Python 3.8.0] 
Python :: python get next item from generator 
Python :: brython implemantation 
Python :: pandas turn counts into probability 
Python :: python average function program 
Python :: importing modules 
Python :: fetch api python 
Python :: create a dictionary from dataframe 
Python :: unique items in a list python 
Python :: insert list 
Python :: print list vertically python 
Python :: download youtube video by python 
Python :: python string: .find() 
Python :: matplotlib get padding from bbox 
Python :: how to mention someone discord.py 
Python :: a list inside a list python 
Python :: python max with custom function 
Python :: np.pad 
Python :: python path absolute 
Python :: function python 
Python :: ceil function in python 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =