Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:15:34+00:00 2026-05-26T23:15:34+00:00

I am a newbie to Python and trying out different ways to optimize and

  • 0

I am a newbie to Python and trying out different ways to optimize and simplify my code.

I have a list of arrays(necessarily in this format) initially empty, which I need to update with arrays, making sure that duplicate entries are not added.

Right now I am doing it the following way, which is the only thing i tried out which works:

if len(where(((array(self.pop_next)-(self.pop[self.top_indv_indx[i]]))==0).sum(1)==len((self.pop[self.top_indv_indx[i]])))[0])<=0):
     self.pop_next.append(self.pop[self.top_indv_indx[i]])

where self.pop_next is my list of arrays and self.pop[self.top_indv_indx[i]] is the array to be added.

I know this Unpythonic and guess that there are much better simple ways to do the same.
Please Help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:15:35+00:00Added an answer on May 26, 2026 at 11:15 pm

    You may want to try with numpy.all(array1 == array2) as condition for an individual array comparison.

    Extension in edit:

    To loop over the list, you may use the following:

    if all((numpy.all(array_to_add != a) for a in array_list)):
        array_list.append(array_to_add)
    

    This compares array_to_add to all elements of array_list by value. Note that all here is __builtin__.all, in contrast to numpy.all. If you did from numpy import * before, this will not work. Use import numpy instead and call functions by full name as in the example above.

    If it is ok to compare by object (i.e. two arrays are only the same if the are the exact same object in memory), use the following simpler variant:

    if array_to_add is not in array_list:
        array_list.append(array_to_add)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie to python and the app engine. I have this code that
I'm newbie in Python. I can't understand why this code does not work: reOptions
I'm a Python newbie, so I'm sure this is easy. Here's the code in
I'm newbie in Python, but this question is not a homework (actually this code
Newbie to Python, so this may seem silly. I have two dicts: default =
I am a python newbie. i was trying out a django tutorial and got
Python newbie here. I'm trying to package a console app following this doc .
i'm a newbie in python , and trying to install libgmail .. this is
I am a newbie to Python and have come across the following example in
I'm a python newbie and starting out with using the Bottle web framework on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.