import numpy as np import random rnstart = random.randint(0, 10) print(rnstart)
ID: 3880741 • Letter: I
Question
import numpy as np
import random
rnstart = random.randint(0, 10)
print(rnstart)
x = np.ones((10,2))
for row in x:
row[0] = rnstart
row[1] = rnstart + 100
rnstart = random.randint(0, 10)
print(x)
fastaSeq = ('')
fasta = open('15small22.fasta', 'r').readlines()
dna = ('')
for line in fasta:
if not line.startswith('>'):
dna += line
#print(list(dna))
dna = list(dna)
print(dna)
y = np.ones((10,2))
#
for i in range(0,5):
np.append(y, dna[x[i,0]:x[i,1]], axis=int)
print(y)
#
#a = np.array([[i]*2 for i in range(10)])
#for i in x:
# for e in i:
# e[i]= rnstart
#a[1] = rnstart + 100
#x = np.ones((10,2)) # need to make this first number (row) 10k, row will be randint, randint + 100
#print(x)
#
#for row in x:
# for e in row:
# e[0] = rnstart
# e[1] = rnstart + 100
#
#
#for i in range(len(x)):
# for j in range(len(x[i])):
# print(j)
# #print(x[i][j])
#x[0] = rnstart
#x[1] = rnstart + 100
#for i, element in range[0::1]:
# enumerate(x):
# for element in x:
# element [0] = rnstart
# element [1] = rnstart + 100
#
##for i, element in enumerate(x):
# # element [0] = rnstart
# # element [1] = rnstart + 100
#print(x)
#print(x[0])
#for i in range(100):
# array = np.array(rnstart, rnstart + 100)
# print(array)
#print(numpy.arange(value, ,100, dtype=None))
Explanation / Answer
By observing the error screenshot:
there is problem with the syntax of append method that we used
np.append(y, dna[x[i,0]:x[i,1]], axis=int) - in this axis = int is the error because according to python documentation the axis argument takes integer numbers as its argument but here we give string as argument so we are getting the error.
if we replace axis with either 1 or 0 we get out required output:
example:
np.append(y, dna[x[i,0]:x[i,1]], axis=0)
if we replace the np.append code in our program as above we can run our program sucussfully with out any errors.
where axis = 0 means it indicate rows
axis = 1 means it indicate column
we have to chage the axis based on our requirement i.e., how we want to append the elements.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.