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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:37:32+00:00 2026-05-23T17:37:32+00:00

Given a matrix A with dimension m x n and the entries in the

  • 0

Given a matrix A with dimension m x n and the entries in the matrix lies [0,1]
For example

A = [0.5 0   0  0.5 0
     0   0.5 0  0   0.5
     1   0   0  0   0]

I would like to calculate sum(sum(a_ij log(a_ij))), where a_ij is the i th row and j th col entry in the matrix A. Since there exist an 0 entry in the matrix, i always get NAN as a result.

How do i consider only non-zero entries to calculate sum(sum(a_ij log(a_ij))) [entropy of the matrix].

  • 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-23T17:37:33+00:00Added an answer on May 23, 2026 at 5:37 pm

    To consider only specific elements of a matrix you can use logical indexing. For example if you only want to select non-zero entries of A you can use A(A~=0). So for your problem the solution can be written:

    sum(A(A~=0).*log(A(A~=0)));
    

    EDIT: wow that is some kind of coincidence, I’ve just seen your comment after posting this. Well, glad you’ve worked it out yourself.

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

Sidebar

Related Questions

Given a double dimension matrix with all positive numbers how do I traverse the
i want to to calculate minimum sum in given two dimensional array #include<iostream> #include<limits.h>
Given 2 matrix A , B with the same dimension, M(x, y) = |A(x,
Given an n-dimensional matrix of values: what is the most efficient way of retrieving
Given an arbitrary 4x4 transformation matrix, how do I find out the center of
Given graph, how could i represent it using adj matrix?. I have read lots
Given a date range how to calculate the number of weekends partially or wholly
I would like to store and load numpy arrays from binary files. For that
Given a data matrix data of M dimensions and N samples, say, data =
The code below calculates the correlation matrix given a covariance matrix. How can I

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.