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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:06:28+00:00 2026-06-15T01:06:28+00:00

I am writing a machine learning code and I struggle to find the way

  • 0

I am writing a machine learning code and I struggle to find the way of having some operations with matrix manipulations instead of iterative way with basic for loops. Do you think using matrix other than iterations make so much difference or it is ignorable performance difference?

  • 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-15T01:06:29+00:00Added an answer on June 15, 2026 at 1:06 am

    Historically loops in matlab were very slow. However, in the versions of Matlab that have the new JIT compile loops can be quite fast.

    In Matlab its advised to avoid loops whenever possible because the language as a whole is designed for vector based operations. When writing matlab code its considered bad style to loop over a vector instead of using vector based math.

    Good matlab code:

    [a b] = deal( rand(10,1) );
    c = a+b;
    

    Bad matlab code:

    [a b] = deal( rand(10,1) );
    c = zero(10,1);
    for i = 1:10
      c(i) = a(i) + b(i);
    

    Both of these implementation are “correct”, however 99% of matlab programmers will use the first implementation. Additionally any matlab programmer would see the first implementation and know exactly what the code means.

    Regarding performance, its hard to say before hand if a vector operation will be faster than a loop, as it really depends on the implementation details. However, in my experience vector functions are rarely slower than loops. I’ve encountered algorithmic problems that I couldn’t solve without a loop. When I discovered the vector based solution it reduced the computation time down from several minutes to less than a second: How can I optimize this indexing algorithm

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

Sidebar

Related Questions

I am writing some Machine Learning code in MATLAB, and I am representing a
I am writing my code in my virtual machine and always committing the folder
I'm interested in writing certain software that uses machine learning, and performs certain actions
I'm writing some code to parse a string into a double, but this string
I am writing a fairly complicated machine learning program for my thesis in computer
I'm learning C++ and writing a binary search tree. The following is the code
I learning how to write a WordPress plugin. I need some help writing some
I'm writing code on a GPU enabled machine, but my code needs to be
Hey some im writing a bootloader using nasm a virtual machine ect. Anyhow, im
I'm writing a tutorial where I demo some rails commands. On my machine rails

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.