Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
111 views
in Python by (120 points)
Create a 3x4 matrix with random numbers with the help of Nampi library, then put the negative numbers inside this matrix into a one-dimensional array.

Please log in or register to answer this question.

1 Answer

0 votes
by (24.8k points)
import numpy as np

# Create a 3x4 matrix with random numbers
matrix = np.random.randn(3, 4)

print("Original Matrix:")
print(matrix)

# Extract negative numbers into a one-dimensional array
negative_numbers = matrix[matrix < 0]

print("\nNegative Numbers Array:")
print(negative_numbers)

In this code, the np.random.randn(3, 4) function generates a 3x4 matrix with random numbers drawn from a standard normal distribution. The condition matrix < 0 creates a boolean mask indicating which elements of the matrix are negative, and then indexing the matrix with this condition extracts the negative numbers.

Related questions

0 votes
1 answer
asked Apr 5, 2023 in Python by kvdevika (118k points)
0 votes
1 answer
asked Apr 5, 2023 in Python by kvdevika (118k points)
0 votes
1 answer
asked Apr 5, 2023 in Python by kvdevika (118k points)
0 votes
1 answer
asked Apr 5, 2023 in Python by kvdevika (118k points)
0 votes
1 answer
asked Apr 5, 2023 in Python by kvdevika (118k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...