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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:35:15+00:00 2026-06-07T23:35:15+00:00

I have a matrix M containing pairs (i.e. arrays of size 2). Given a

  • 0

I have a matrix Mcontaining pairs (i.e. arrays of size 2). Given a pair p, how can I get a 2D matrix M'containing the result of the scalar product of p and each element of M?

    (0, 0) (0, 1)                             8 5
M = (1, 0) (1, 1)       p = (2, 2)       M' = 5 2
    (2, 0) (2, 1)                             4 1

M and p are defined :

M =. 3 2 2 $ 0 0 0 1 1 0 1 1 2 0 2 1
p =. 2 2

I have an implementation of scalar product in J :

sp =. +/ @: *: @: -

It works on pairs :

    0 0 sp p
8
    0 1 sp p
5

But not on the full matrix, because of bad length :

    p sp M
|length error: sp
|   p     sp M

How should I deal with that ? This is probably easy for J geniuses, but I’m just a poor newbie.

  • 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-07T23:35:17+00:00Added an answer on June 7, 2026 at 11:35 pm

    Use

    p sp"1 M
     8 5
     5 2
     4 1
    

    You want sp here to read first-rank cells of M:

    <"1 M
    ┌───┬───┐
    │0 0│0 1│
    ├───┼───┤
    │1 0│1 1│
    ├───┼───┤
    │2 0│2 1│
    └───┴───┘
    

    so sp"1 will work on each cell (p sp 0 0, p sp 0 1, etc). sp (infinite rank) tries to apply sp once for the whole matrix M.

    Likewise sp"2 will apply sp on second-rank cells of M:

    <"2 M
     ┌───┬───┬───┐
     │0 0│1 0│2 0│
     │0 1│1 1│2 1│
     └───┴───┴───┘
    

    so

    p sp"2 M
     8 5
     2 5
     0 5
    

    (the pairs: p sp 2 2 $ 0 0 0 1, p sp 2 2 $ 1 0 1 1 and p sp 2 2 $ 2 0 2 1)

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

Sidebar

Related Questions

I have a matrix m of zeros and a data-frame df containing records I
I have written the code below to generate a matrix containing what is, to
I have a matrix ( X ) of doubles containing time series. Some of
I have a text file being saved by a matrix library containing a 2D
I have an ASCII file containing a matrix of real numbers. I want to
I have some large matrices of data, and a a two column matrix containing
I have an array $matrix_part , containing arrays, and I want to rekey the
I have to generate two random sets of matrices Each containing 3 digit numbers
Let's say I have a 100x100 matrix A, and I want to get another
I have a matrix containing 4320 entries for example: P=[ 26 29 31 33

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.