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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:49:34+00:00 2026-05-30T13:49:34+00:00

Edit : I’ve found what the problem boils down to: If you run this

  • 0

Edit: I’ve found what the problem boils down to:

If you run this code:

A = ones((10,4))
view = A[:,1]
view.fill(7)
A

or

A = ones((10,4))
view = A[:,1:3]
view.fill(7)
A

You’ll see that the columns of A change

If you run this:

A = ones((10,4))
view = A[:,(1,2)]
view.fill(7)
A

There’s no side effects on A. Is this behavior on purpose or a bug?

I have a function that calculates the amount I have to rotate certain columns of x,y points in a matrix. The function only takes one input – a matrix mat:

def rotate(mat):

In the function, I create views to make working with each section easier:

rot_mat = mat[:,(col,col+1)]

Then, I calculate a rotation angle and apply it back on the view that I had created before:

rot_mat[row,0] = cos(rot)*x - sin(rot)*y
rot_mat[row,1] = sin(rot)*x + cos(rot)*y

If I perform this in the main body of my program, the changes to my rot_mat view would propagate to the original matrix mat. When I turned it into a function, the views stopped having side effects on the original matrix. What’s the reasoning for this and is there any way to get around it? I should also note that it isn’t changing mat within the function itself. At the end, I just try to return mat but no changes have been made.

Full code for function:

def rotate(mat):
    # Get a reference shape
    ref_sh = 2*random.choice(range(len(filelist)))
    print 'Reference shape is '
    print (ref_sh/2)
    # Create a copy of the reference point matrix
    ref_mat = mat.take([ref_sh,ref_sh+1],axis=1)
    # Calculate rotation for each set of points
    for col in range(len(filelist)):
        col = col * 2 # Account for the two point columns
        rot_mat = mat[:,(col,col+1)]
        # Numerator = sum of wi*yi - zi*xi
        numer = inner(ref_mat[:,0],rot_mat[:,1]) - inner(ref_mat[:,1],rot_mat[:,0])
        # Denominator = sum of wi*xi + zi*yi
        denom = inner(ref_mat[:,0],rot_mat[:,0]) + inner(ref_mat[:,1],rot_mat[:,1])
        rot = arctan(numer/denom)
        # Rotate the points in rot_mat.  As it's a view of mat, the effects are
        # propagated.
        for row in range(num_points):
            x = rot_mat[row,0]
            y = rot_mat[row,1]
            rot_mat[row,0] = cos(rot)*x - sin(rot)*y
            rot_mat[row,1] = sin(rot)*x + cos(rot)*y
    return mat
  • 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-30T13:49:36+00:00Added an answer on May 30, 2026 at 1:49 pm

    When you do view = A[:,(1,2)] you are using advanced indexing (Numpy manual: Advanced Indexing), which means that the array returns a copy, not a view. It’s advanced because your indexing object is a tuple “containing at least one sequence” (the sequence being the tuple (1,2)). The total explicit selection object obj in your case would equal (slice(None), (1,2)), i.e. A[(slice(None), (1,2))] returns the same thing as A[:,(1,2)].

    As larsmans suggests above, it seems that __getitem__ and __setitem__ behave differently for advanced indexing, which makes sense, because assigning values to a copy would have no use (the copy would not be stored).

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

Sidebar

Related Questions

Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit: I have solved this by myself. See my answer below I have set
EDIT Leaving this for posterity, but nearly a year later, to get down voted,
EDIT After staring at this for 2 days, I do see one issue. I
EDIT I tried debugging this with xdebug and netbeans. It's weird that the exports
Edit: This is currenty kinda resolved, Instead of struggling with the problem, I started
[EDIT: Problem solved. Please see my answer below.] In my app I call the
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE

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.