Knowee
Questions
Features
Study Tools

Convert heights and positions, which are regular lists, to numpy arrays. Call them np_heights and np_positions

Question

Convert heights and positions to numpy arrays

Convert heights and positions, which are regular lists, to numpy arrays. Call them np_heights and np_positions.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is how you can convert regular lists to numpy arrays in Python:

First, you need to import the numpy library. If you haven't installed it yet, you can do so using pip:

pip install numpy

Then, in your Python script, you can convert your lists to numpy arrays like this:

import numpy as np

# let's assume heights and positions are your lists
heights = [1.80, 1.85, 1.75, 1.90]
positions = ['GK', 'M', 'A', 'D']

# convert lists to numpy arrays
np_heights = np.array(heights)
np_positions = np.array(positions)

Now, np_heights and np_positions are numpy arrays.

This problem has been solved

Similar Questions

Given a 2D list, create a numpy 2D array using it.Note: Given 2D list is [[1, 2, 3], [4, 5, 6], [7, 8, 9]]Print the Numpy array.

Which function is used for reshape a NumPy array in Python?Answer choicesSelect an optionreshape_array()reshape()reshape_arrays()reshape_arr()

What is a correct syntax to create a NumPy array?np.createArray([4,5,6])np.numpyArray([4,5,6])np.array([4,5,6])np.create_array([4,5,6])

What is a correct syntax to create a NumPy array?np.array([4,5,6])np.numpyArray([4,5,6])np.createArray([4,5,6])np.create_array([4,5,6])

What is the order of the array np_c?np_a = np.array( [[1,2] , [3,4]])np_b = np.array( [[5,6] , [7,8]])np_c = np.hstack((np_a, np_b))print( np_c.shape )

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.