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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:56:56+00:00 2026-05-18T03:56:56+00:00

I can’t get simple matrix operations to work on data, for the life of

  • 0

I can’t get simple matrix operations to work on data, for the life of me I haven’t been able to figure out what I’m doing incorrectly:

data = np.genfromtxt(dataset1, names=True, delimiter=",", dtype=float)

X = np.matrix(data)
print(X.T*X)

Traceback (most recent call last):
  File "genfromtxt.py", line 11, in <module>
    print(X.T*X)
  File "/usr/lib/pymodules/python2.6/numpy/matrixlib/defmatrix.py", line 319, in __mul__
    return N.dot(self, asmatrix(other))
TypeError: can't multiply sequence by non-int of type 'tuple'

print(data) gives:

[ (3.0, 32.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 9.0, 0.0, 5.5606799999999996, 9.0)
 (4.0, 43.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 9.0, 0.0, 5.7203099999999996, 16.0)
 (5.0, 40.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 9.0, 0.0, 5.9964500000000003, 25.0)
 ...,
 (5.0, 50.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 12.0, 0.0, 6.2146100000000004, 25.0)
 (6.0, 50.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 12.0, 0.0, 6.2915700000000001, 36.0)
 (7.0, 50.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 12.0, 0.0, 6.3716100000000004, 49.0)]

EDIT:

Further, this code

reader = csv.reader(open(dataset1, 'r'))
header = reader.next()
X = np.array([[float(col) for col in row] for row in reader])

print(X.shape)
print(X.T.shape)
print(X * X.T)

gives this output:

(4165, 13)
(13, 4165)
Traceback (most recent call last):
  File "genfromtxt.py", line 17, in <module>
    print(X * X.T)
ValueError: shape mismatch: objects cannot be broadcast to a single shape
>>> 
  • 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-18T03:56:56+00:00Added an answer on May 18, 2026 at 3:56 am

    The problem with the second example seems to be that the operator * performs element-wise multilpication for NumPy arrays. Presumably you would like to perform a matrix multiplication. There are two options to do this:

    1. Use numpy.matrix instead of numpy.array — then multiplication will be matrix multiplication and powers by integer exponents will work as expected.

    2. Use numpy.dot(A, B) instead of A*B — this will perform matrix multiplication for both arrays and matrices.

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

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can anyone tell me what i am doing wrong? I am trying to get
Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
Can somebody tell me how to get mod_rewrite to rename this: our-work-section.php?id=3&title=something to our-work-section/something/3
Can I get a 'when to use' for these and others? <% %> <%#
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can some one Guide me to work with these things... What is Model popup

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.