Making an arrey of a zipped list, Python

In summary, to make an array out of a list in Python, you can use the zip function to combine two lists into a new one. In this conversation, the person is asking for a more detailed explanation of how to do this. The other person explains that Python does not have arrays, but instead has lists. They also mention using the zip function to create a new list. They provide an example using the scitools library and a function to calculate the value of h for each element in the array. Finally, they use a for loop and the zip function to print out the values in the new array.
  • #1
MaxManus
277
1
How do you make an arrey out of this list?

for X, H in zip(xarrey,harrey):
print "%.2f %.5f" % (X,H)
 
Technology news on Phys.org
  • #2
Can you give me a more detailed explanation? I don't know what list you're talking about, or what you mean by "making an array" out it. Python doesn't have "arrays," it has lists.

- Warren
 
  • #3
from scitools.all import *

def h(x):
return (1/(sqrt(2*pi)))*e**-(0.5*x**2)

xarray = linspace(-4,4,10)
x = xarray
harrey = zeros(len(xarrey))

for i in xrange(len(xarray)):
harrey = h(x)

for X, H in zip(xarray,harray):
print "%.2f %.5f" % (X,H)
 

What is an array and how is it used in Python?

An array is a data structure that stores a collection of elements of the same type. In Python, arrays are implemented using the built-in "array" module. Arrays are used to efficiently store and manipulate large amounts of data.

What is a zipped list in Python?

A zipped list in Python is a list that combines multiple lists into a single list of tuples. The "zip" function in Python takes in two or more lists and returns an iterator of tuples, where each tuple contains elements from all the lists. This is useful for creating data structures that store related data together.

How do I create an array from a zipped list in Python?

To create an array from a zipped list in Python, you can use the "array" module and the "zip" function. First, import the array module. Then, use the "zip" function to combine the lists and pass the result to the "array" function. This will create an array of tuples, where each tuple contains elements from the zipped lists.

Can I unzip a zipped list in Python?

Yes, you can unzip a zipped list in Python using the "zip" function. Simply pass the zipped list to the "zip" function again and use the "list" function to convert the iterator into a list. This will return the original lists that were zipped together.

What are some use cases for using a zipped list in Python?

Zipped lists are useful in situations where you need to store related data together. For example, you can use zipped lists to store data from a CSV file, where each list represents a column of data. Zipped lists are also helpful when working with large amounts of data, as they can improve the efficiency of your code.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
2
Views
646
  • Programming and Computer Science
Replies
5
Views
1K
Replies
6
Views
638
  • Programming and Computer Science
Replies
5
Views
988
  • Programming and Computer Science
2
Replies
43
Views
3K
  • Programming and Computer Science
Replies
3
Views
311
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
7
Views
418
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top