0

How to make append multiple times in for loop to get same results for B like below

import numpy as np

B1 = np.linspace(0,1,7)
B2 = np.linspace(3,8,7)

B = np.append(B1, B2)

B = np.append(B, B2)
B = np.append(B, B2)
B = np.append(B, B2)
B = np.append(B, B2)

so far try something like this but i don't have anny ideas

n = 5 
for i in range(n):
    B[i] = np.append(B, B2) 

2 Answers 2

1

You can use np.tile() to append multiple times along a certain axis.

B = np.append( B1, np.tile(B2, (1, 5)) )
Sign up to request clarification or add additional context in comments.

Comments

0
n = 5 
for i in range(n):
    B = np.append(B, B2)

2 Comments

No need for brackets [i]
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.