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

  • Home
  • SEARCH
  • 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 6795313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:19:45+00:00 2026-05-26T18:19:45+00:00

I want to apply a transformation to certain columns of a record array and

  • 0

I want to apply a transformation to certain columns of a record array and reassign these values. What is the canonical way to do this?

List = [['a',.3,.3],
        ['b',-.5,.4]]

Arr = np.rec.fromrecords(List,names=['id','var1','var2'])

And I want to apply some scaling to some variables. I’ll let this be an example but in general the scaling may be more complex than subtracting means.

scale = lambda x: x - x.mean(0)

This does not work

Arr[['var1','var2']].mean(0)
TypeError: cannot perform reduce with flexible type

So I have to convert to an unstructured array first, but then how to reassign back to the record array? Do I loop?

Unstr = Arr[['var1','var2']].view('float').reshape(len(Arr),-1)

Arr[['var1','var2']] = scale(Unstr)

IndexError: unsupported iterator index
  • 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-26T18:19:46+00:00Added an answer on May 26, 2026 at 6:19 pm

    Why don’t you scale variables one by one?

    In [13]: %paste
    import numpy as np
    
    List = [['a',.3,.3],
            ['b',-.5,.4]]
    
    scale = lambda x: x - x.mean()
    Arr = np.rec.fromrecords(List,names=['id','var1','var2'])
    
    vars_to_scale = ['var1', 'var2']
    for var in vars_to_scale:
        Arr[var] = scale(Arr[var])
    print Arr
    ## -- End pasted text --
    [('a', 0.4, -0.04999999999999999) ('b', -0.4, 0.050000000000000044)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want apply margin property for my html newsletter But Gmail ignores this CSS
I want to apply a Storyboard to my Rectangle Fill like this: <Rectangle Name=MyRectangle
I want to apply cycle to the div block with dynamic content. This content
I want to apply or 'bake' a transformation of several paths in Raphael JS
I want to apply a translate transformation to a <div> , and then be
I want to apply texture to the transparent png(bitmap), but I don't want to
I want to apply scaling animation to UIButton.When user drag button upside of the
i want to apply masking over the textinput that need to get SSN from
I want to apply the following Style to my Polygon : <Style xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:s=clr-namespace:System;assembly=mscorlib
I want to apply a different hyper link style to the following two things:

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.