পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Friday, March 24, 2017

NumPy - Array Creation Routines

A new ndarray object can be constructed by any of the following array creation routines or using a low-level ndarray constructor.

numpy.empty

It creates an uninitialized array of specified shape and dtype. It uses the following constructor −
numpy.empty(shape, dtype = float, order = 'C')
The constructor takes the following parameters.

S.No Parameter & Description
1. Shape
Shape of an empty array in int or tuple of int
2. Dtype
Desired output data type. Optional
3. Order
'C' for C-style row-major array, 'F' for FORTRAN style column-major array

Example

The following code shows an example of an empty array.
import numpy as np 
x = np.empty([3,2], dtype = int) 
print x
The output is as follows −
[[22649312    1701344351] 
 [1818321759  1885959276] 
 [16779776    156368896]]
Note − The elements in an array show random values as they are not initialized.

numpy.zeros

Returns a new array of specified size, filled with zeros.
numpy.zeros(shape, dtype = float, order = 'C')
The constructor takes the following parameters.
S.No Parameter & Description
1. Shape
Shape of an empty array in int or sequence of int
2. Dtype
Desired output data type. Optional
3. Order
'C' for C-style row-major array, 'F' for FORTRAN style column-major array

Example 1

# array of five zeros. Default dtype is float 
import numpy as np 
x = np.zeros(5) 
print x
The output is as follows −
[ 0.  0.  0.  0.  0.]

Example 2

import numpy as np 
x = np.zeros((5,), dtype = np.int) 
print x
Now, the output would be as follows −
[0  0  0  0  0]

Example 3

# custom type 
import numpy as np 
x = np.zeros((2,2), dtype = [('x', 'i4'), ('y', 'i4')])  
print x
It should produce the following output −
[[(0,0)(0,0)]
 [(0,0)(0,0)]]         

numpy.ones

Returns a new array of specified size and type, filled with ones.
numpy.ones(shape, dtype = None, order = 'C')
The constructor takes the following parameters.
S.No Parameter & Description
1. Shape
Shape of an empty array in int or tuple of int
2. Dtype
Desired output data type. Optional
3. Order
'C' for C-style row-major array, 'F' for FORTRAN style column-major array

Example 1

# array of five ones. Default dtype is float 
import numpy as np 
x = np.ones(5) 
print x
The output is as follows −
[ 1.  1.  1.  1.  1.]

Example 2

import numpy as np 
x = np.ones([2,2], dtype = int) 
print x
Now, the output would be as follows −
[[1  1] 
 [1  1]]

No comments:

Post a Comment