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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:08:26+00:00 2026-06-14T22:08:26+00:00

I’m having trouble using vq.whiten from scipy.cluster to normalise my data. I’m passing in

  • 0

I’m having trouble using vq.whiten from scipy.cluster to normalise my data. I’m passing in a numpy array which has had missing feature values filled in with the average for each feature.

The line it gets stuck on is:

data = scipy.cluster.vq.whiten(self.imputed)

This is the code I’m using to replace the missing data.

imputed = np.array([self.masked[:,i].filled(self.masked[:,i].mean()) 
                   for i in range(np.shape(self.masked)[1])])
self.imputed = np.transpose(imputed)

I’m sure there’s a better way of doing this part too, quite apart from the fact it seems to be breaking my code. It seems an ugly way of going about it and that normally means there’s a better way with Python.

I’ve tried slicing down how much of the array I send to whiten but no matter what I get the following in the Traceback.

Traceback (most recent call last):
  File "C:\Users\jamie.bull\workspace\Metadata\src\draft_workflow.py", line 87, in <module>
    dataset.cluster()
  File "C:\Users\jamie.bull\workspace\Metadata\src\draft_workflow.py", line 59, in cluster
    data = scipy.cluster.vq.whiten(self.imputed)
  File "C:\Enthought\Python27\lib\site-packages\scipy\cluster\vq.py", line 131, in whiten
    std_dev = std(obs, axis=0)
  File "C:\Enthought\Python27\lib\site-packages\numpy\core\fromnumeric.py", line 2467, in std
    return std(axis, dtype, out, ddof)
AttributeError: sqrt

The clustering works fine with the same dataset without any missing data so I’m at a loss for what to try next.

Edit:
I tried printing out the type of each item in imputed for both the full data set and the one with missing data using:

for item in imputed:
    print type(item)

The difference between the two is that when the version which hasn’t had the mean substitution and transpose called on it has one numpy.ndarray for each row while the one which has been mean substituted has one for each column.

  • 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-14T22:08:27+00:00Added an answer on June 14, 2026 at 10:08 pm

    I’ve solved this one now so I’ll put the answer here for future lost souls. The problem was that my mean replacement was replacing the missing values with floats when the original data was stored as numpy.float64.

    The solution is to run the list comprehension and follow it by setting the dtype to np.float64. It seems that whiten doesn’t like to receive mixed data types.

    Also, solving the ugliness problem of having to transpose after the list comprehension, I rediscovered np.column_stack(). The working function is now:

    def mean_impute(self):
        imputed = np.column_stack(self.masked[:,i].filled(self.masked[:,i].mean()) 
                   for i in range(np.shape(self.masked)[1]))
        self.imputed = np.array(imputed, dtype=np.float64)
    

    Edited to add

    A long time ago now but I thought I’d update here. I would now use pandas for data handling and use pandas and fill_na() for this situation.

    The offending line in the OP could be replaced with:

    imputed = self.masked.fillna(self.masked.mean())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have an array which has BIG numbers and small numbers in it. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but

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.