Ask Your Question
0

How can a vector be divided by a predetermined interval in DolphinDB?

asked 2023-05-19 18:11:03 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-19 18:21:01 +0000

pufferfish gravatar image

In DolphinDB, to divide a vector by a predetermined interval, you can use the "div" or "/" operator.

For example, suppose we have a vector "v" containing the numbers [2, 4, 6, 8, 10], and we want to divide each element by 2, we can use the following code:

v = [2, 4, 6, 8, 10];
v = v / 2;

This will result in a new vector "v" containing [1, 2, 3, 4, 5], where each element of the original vector has been divided by 2.

Alternatively, if we want to divide each element in the vector by a different predetermined interval, we can create a new vector containing the intervals we want to use and use the "div" or "/" operator in combination with the dot (.) operator, which performs element-wise operations.

For example, suppose we have the same vector "v" as before, but now we want to divide each element by a different predetermined interval stored in a vector "intervals" containing [2, 4, 6, 8, 10]. We can use the following code:

v = [2, 4, 6, 8, 10];
intervals = [2, 4, 6, 8, 10];
v = v .div intervals;

This will result in a new vector "v" containing [1, 1, 1, 1, 1], where each element of the original vector has been divided by the corresponding element in the "intervals" vector.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-19 18:11:03 +0000

Seen: 7 times

Last updated: May 19 '23