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 8168557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:34:05+00:00 2026-06-06T20:34:05+00:00

I am loading a file data.imputation which is 2 dimensional in variable ‘x’ .

  • 0

I am loading a file “data.imputation” which is 2 dimensional in variable 'x'. Variable 'y' is a copy of 'x'. I pop the first array from 'y' (y is 2D). Why is the change reflected on x? (The first array from 'x' is also popped)

ip = open('data.meanimputation','r')
x = pickle.load(ip)
y = x
y.pop(0)

At the start, len(x) == len(y). Even after y.pop(0), len(x) == len(y). Why is that? And how can I avoid it?

  • 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-06-06T20:34:06+00:00Added an answer on June 6, 2026 at 8:34 pm

    use y = x[:] instead of y = x. y = x means both y and x are now pointing to the same object.

    Take a look at this example:

    >>> x=[1,2,3,4]
    >>> y=x
    >>> y is x
    True          # it means both y and x are just references to a same object [1,2,3,4], so changing either of y or x will affect [1,2,3,4]
    >>> y=x[:]     # this makes a copy of x and assigns that copy to y,
    >>> y is x     # y & x now point to different object, so changing one will not affect the other.
    False
    

    If x is a list is list of list then [:] is of no use:

    >>> x= [[1,2],[4,5]]
    >>> y=x[:]   #it makes a shallow copy,i.e if the objects inside it are mutable then it just copies their reference to the y
    >>> y is x
    False         # now though y and x are not same object but the object contained in them are same 
    >>> y[0].append(99)
    >>> x
    [[1, 2, 99], [4, 5]]
    >>> y
    [[1, 2, 99], [4, 5]]
    >>> y[0] is x[0]
    True  #see both point to the same object
    

    in such case you should use copy module’s deepcopy() function , it makes non-shallow copies of object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am loading data from table to flat file destination, where my flat file
I have a flash file that is loading data from XML file. After I
I'm reading data from a file -> saving into DB -> Loading my Custom
In my application, I'm loading some data from a file. This can fail and
I have tried using a example file using PHPExcel script to extract data from
Based on the function below, it is used to load data from file .dat.
How should I quit a Qt Program, e.g when loading a data file, and
I am using PHP to expose vehicle GPS data from a CSV file. This
I am using PyMySQL-0.5.0 and facing an obscure'ish error/exception when loading data from a
I have a data file full of numbers I'm loading into a vector of

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.