Answer to Question #314810 in Python for xxx

Question #314810

1.Convert the 1-D array to 3-D array


a = np.array([x for x in range(32)])



Answer:



print(o)



Output:


array([[[ 0, 1, 2, 3, 4, 5, 6, 7],


[ 8, 9, 10, 11, 12, 13, 14, 15]],



[[16, 17, 18, 19, 20, 21, 22, 23],


[24, 25, 26, 27, 28, 29, 30, 31]]])



2.Convert the value in the array to appropriate data type


a = np.array([[7.2, 5.4, 9.3],


[3.8, 6.7, 8.5]])



Answer:



print(o)



Output:


[[7 5 9]


[3 6 8]]



3.Extract value in between 7 to 15 from the given array


a = np.array([2, 6, 1, 9, 10, 3, 27])



Answer:



print(o)



Output:


[ 8 12 9 11]

1
Expert's answer
2022-03-21T02:03:29-0400

1.

o = a.reshape(4,8)
print(o)


2.

o = a.astype('int32')
print(o)


3.

o = []
def extract_values(a):
    for element in a:
        if (element > 7) and (element < 15):
            o.append(element)
    return np.array(o)

extract_values(a)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS