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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:19:43+00:00 2026-06-01T22:19:43+00:00

I have a the following code: p = classp(); for i in range(1,10): x

  • 0

I have a the following code:

p = classp();
for i in range(1,10):
   x = numpy.array([[2],[4],[5]])
   print p.update(x)

class classp:
   def __init__(self):
       self.mymodel = array([2*x[1]], [3*x[0]], [x[2]]);
   def update(self, x):
       return self.mymodel #replace x(0)...x(1) with the given parameter

My question is related the code above, I would like to define a model using sympy if it’s possible, afterwards in the update function replace the sympy variables with the x values. Is it possible? How can I do that?

  • 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-01T22:19:44+00:00Added an answer on June 1, 2026 at 10:19 pm

    I can propose you two solutions.

    Firstly, there is DeferedVector that was created for use with lambdify:

    In [1]: from sympy.matrices import DeferredVector
    
    In [2]: v = DeferredVector('v')
    
    In [3]: func = lambdify(v, Matrix([v[1], 2*v[2]]))
    
    In [4]: func(np.array([10,20,30]))
    Out[4]: 
           [[20] 
            [60]]
    

    However lambdify does too much magic for my taste.

    Another option is to use the .subs method:

    In [11]: x1, x2, x3 = symbols('x1:4')
    
    In [12]: m = Matrix([x2,2*x1,x3/2])
    
    In [13]: m.subs({x1:10, x2:20, x3:30})
    Out[13]: 
            ⎡20⎤
            ⎢  ⎥
            ⎢20⎥
            ⎢  ⎥
            ⎣15⎦
    

    You can create the dictionary for the substitution like that:

    dict(zip(symbols('x1:4'), your_value_array)).

    Do not forget that all the return objects are sympy matrices. To convert them to numpy arrays just use np.array(the_matrix_in_question) and do not forget to specify the dtype, otherwise it will default to dtype=object.

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

Sidebar

Related Questions

consider the following code: class MyClass(object): def __init__(self): self.data_a = np.array(range(100)) self.data_b = np.array(range(100,200))
I have the following code class Board: def __init__(self, size=7): self._size = size self._list,
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following code: class MyClass module MyModule class << self attr_accessor :first_name
Look at the following Python code: def function(x): return x, x+1 sequence = range(5)
I have following code class User attr_accessor :name end u = User.new u.name =
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: class TimeOutException {}; template <typename T> class MultiThreadedBuffer {
I have the following code: class outer { struct inner { int var1; int
I have the following code: class Foo<T> where T : struct { private T

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.