<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[datascienceoffuture - Medium]]></title>
        <description><![CDATA[Python Basics &amp; Exploratory Data Analysis (EDA),Regression &amp; Web Scraping,SQL, Classification &amp; Web Interface Development,Clustering, NoSQL, Natural Language Processing &amp; Recommendation Systems,DataBricks, Spark, Spark ML , Spark ALS,numpy,pandas,matplotlib, - Medium]]></description>
        <link>https://medium.com/datascienceoffuture?source=rss----4a3273f426e0---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>datascienceoffuture - Medium</title>
            <link>https://medium.com/datascienceoffuture?source=rss----4a3273f426e0---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 21:53:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/datascienceoffuture" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NumPy Fundamentals on Data Science]]></title>
            <link>https://medium.com/datascienceoffuture/numpy-fundamentals-on-data-science-deb023d79bcd?source=rss----4a3273f426e0---4</link>
            <guid isPermaLink="false">https://medium.com/p/deb023d79bcd</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Barış Sinanoğlu]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 05:55:38 GMT</pubDate>
            <atom:updated>2023-07-10T00:59:35.972Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, the NumPy library in the Python programming language, which is the most popular language in the field of data science, serves as the equivalent of numerical Python expressions. NumPy has established itself as an incredibly robust standard in its field, catering to both novice users and expert coding individuals and teams. Like other Python libraries, it operates under an open-source structure.</p><p>NumPy encompasses multidimensional array and matrix data structures, enabling us to swiftly and efficiently execute a wide range of operations on them. Furthermore, NumPy facilitates statistical calculations, fast and efficient data manipulation between arrays, and integrates seamlessly with many frequently used data science libraries. Some notable examples of these libraries include pandas, matplotlib, and seaborn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*vLmCE-IMC2Pq-K26MctH6g.png" /></figure><p>ndarray is the main data structure in NumPy. It represents the concept of an “n-dimensional array.” These arrays must be of the same data type, which is understandable because scientific calculations and data analysis, both vital for data science and data manipulation applications, require a certain data type to perform mathematical operations.</p><p>Ndarrays in NumPy are arrays with a fixed shape of any size. The number of dimensions and shape properties express the structure of the ndarray.<br>1D ndarray (one-dimensional array) = vector<br>2D ndarray (2D array) = Matrix</p><p>One of the key features of NumPy is its vectorization capability, which allows applying operations to the entire array at once, instead of applying the same operation to individual elements one by one. Additionally, NumPy’s memory block structure provides fast access, making it ideal for working with large volumes of datasets.</p><p>To install NumPy in Python, you can use the following commands:</p><p><strong>pip install numpy</strong></p><p>or</p><p><strong>conda install numpy</strong></p><p>When using a package or library in the Python programming language, you need to make it accessible by importing it. To import the NumPy library, you can use the following command:</p><p><strong>import numpy as np</strong></p><p>The abbreviation “np” is commonly used to refer to NumPy, providing a more concise and widely accepted way of writing code.</p><p>Let’s delve a bit deeper into arrays. Arrays are at the core of the NumPy library as they allow us to access or interpret specific elements within the array. A NumPy array can contain various types of data, such as positive integers, boolean (True/False) expressions, another array (nested), or a tuple of different integer values. However, it’s important to note that NumPy arrays must consist of values of the same type.</p><p>In the Python programming language, like in all other programming languages, indexing operations start at 0. Let’s provide an example:</p><p><strong>a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])</strong><br>In this example, let’s print the result we desire using the print command, which is the most basic Python command:<br><strong>print(a[0])</strong></p><p>The array “a” consists of three nested arrays. We access the first index element in the array “a” and print it. The output will be:<br><strong>[1, 2, 3]</strong></p><p>Here are some basic array commands in NumPy:</p><p><strong>np.array()<br>np.zeros()<br>np.ones()<br>np.empty()<br>np.arange()<br>np.linspace()<br>dtype</strong></p><p>Let’s proceed with examples:</p><p><strong>import numpy as np<br>a = np.array([1, 2, 3, 4])<br>print(a)</strong><br>Output: <strong>[1, 2, 3, 4]</strong></p><p>We have made the NumPy library accessible, defined an array named “a” with its elements, and printed it on the screen.</p><p><strong>np.zeros(3)</strong><br>Output: <strong>array([0., 0., 0.])</strong><br>This command creates a 3-element array filled with zeros.</p><p><strong>np.ones(4)</strong><br>Output: <strong>array([1., 1., 1., 1.])</strong><br>This command creates a 4-element array filled with ones.</p><p><strong>np.empty(3)</strong></p><p><strong>np.arange(4)</strong><br>Output: <strong>[0, 1, 2, 3]</strong><br>In this example, we printed all positive integer numbers up to the number specified (excluding 4) in ascending order.</p><p><strong>np.arange(2, 20, 4)</strong><br>Output: <strong>[2, 6, 10, 14, 18]</strong><br>In this example, we specified the starting number, the maximum number (excluding 20), and the step size (4) to print the array on the screen.</p><p><strong>np.linspace(0, 80)</strong><br>Output:<strong> [0., 10., 20., 30., 40., 50., 60., 70., 80.]</strong><br>In this code block, we created an array with equally spaced values in a given range, including the start value (0) and end value (80).</p><p><strong>array = np.ones(3, dtype=int)</strong><br><strong>print(array)</strong><br>By specifying the data type as int (integer), we override the default float64 data type. This code block gives us a result with integer data type instead of float64.</p><p>Output: <strong>array([1, 1, 1])</strong></p><p>Adding, deleting, and sorting elements in arrays can be achieved using the following functions:<br><strong>np.append()<br>np.delete()<br>np.sort()</strong></p><p>For example, let our array be:<br><strong>array = np.array([1, 2, 3, 4, 5, 6, 7])</strong></p><p>You can add elements to the array using np.append():<br><strong>np.append(array, [1, 2, 3])</strong></p><p>The array will now be:<strong> [1, 2, 3, 4, 5, 6, 7, 1, 2, 3]</strong></p><p>To delete an item from the array, you can use np.delete(). The element specified by its index will be removed from the array:<br>np.delete(array, 1)</p><p>The array will become: <strong>[1, 3, 4, 5, 6, 7]</strong></p><p>Sorting an array can be achieved with np.sort():<br><strong>array = np.array([2, 1, 5, 3, 7, 4, 6, 8])<br>np.sort(array)</strong></p><p>The array will be: <strong>[1, 2, 3, 4, 5, 6, 7, 8]</strong></p><p>The ndarray.ndim property specifies the number of axes or dimensions of the array. The ndarray.size property tells you the total number of elements in the array, and the ndarray.shape property displays an array of integers indicating the number of elements stored in each dimension of the array.</p><p>Indexing and slicing operations allow you to access specific elements or sequences of elements in an array. Here are some examples:<br><strong>data = np.array([1, 2, 3, 4])<br>print(data[0]) # Print the first element of the data array with index 0<br>print(data[2]) # Print the third element of the data array with index 2<br>print(data[0:3]) # Print the first three elements in sequence<br>print(data[1:]) # Print the rest starting from index 1<br>print(data[-2:]) # Print the last two elements in the data array</strong></p><p>You can use mathematical expressions with NumPy. For example, you can easily print elements less than 3 in our data array as follows:</p><p><strong>x = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])<br>print(x[x &lt; 5])</strong></p><p>By using the logical expression x &lt; 5, we printed the numbers less than 5 in the x array.</p><p>If you want to access elements within certain number ranges, you can use the logical operators “and” and “or”. In NumPy, “&amp;” represents “and” and “|” represents “or”.</p><p>To find sums, maximum and minimum values, and perform other common operations in arrays, NumPy provides various functions such as np.sum(), np.max(), np.min(), etc.</p><p>NumPy also offers functions for trigonometric calculations (np.sin, np.cos, np.tan),</p><p>Thus, we have reached the sum of all elements in the array x.</p><p>More actions:</p><p><strong>max()<br>min()</strong></p><p><strong>x.max()</strong></p><p>Output : <strong>25</strong></p><p>We got the highest number in the X array.</p><p><strong>x.min()</strong></p><p>Output : <strong>8</strong></p><p>We got the smallest number in the X array.</p><p>Sizes and shapes of arrays:</p><p><strong>np.shape()<br>np.size()</strong></p><p><strong>x = np.array([[1, 1], [2, 2]])<br>np.shape(x)</strong><br>Output: <strong>(2, 2)</strong> In other words, we have reached the information that our array named x consists of 2 rows and 2 columns. The first value represents the row, the second value represents the column.</p><p><strong>x = np.array([[1, 1], [2, 2]])<br>np.size(x)</strong><br>Output : <strong>4</strong></p><p>Here we have reached the total number of elements of our array, which we call x.</p><p>Generating random numbers<br>NumPy provides us with convenience for random numbers, which have a very important place from a simple dice program to machine learning algorithms.</p><p>NumPy’s random module supports different distributions, samplings, and random data generation for random number generation. Some of the commonly used functions are:</p><p><strong>np.random.rand</strong>: Generates random numbers with a uniform (equal probability) distribution between 0 and 1.<br><strong>np.random.randn</strong>: generates random numbers with standard normal distribution.<br><strong>np.random.randint</strong>: generates integer random numbers in a given range.<br><strong>np.random.choice</strong>: randomly selects items from a given array or list.<br><strong>np.random.shuffle</strong>: shuffles an array in place.<br>Using these functions, it can generate random numbers, perform sampling, and perform random operations on data manipulation.</p><p>Obtaining unique items and counts<br>You can easily find unique elements in an array with np.unique.</p><p><strong>array = np.array([2, 1, 5, 2, 1, 3, 5, 3, 4, 4])</strong></p><p><strong>unique_values = np.unique(array)</strong></p><p><strong>print(unique_values)</strong></p><p>Output : <strong>[1 2 3 4 5]</strong></p><p>Another usage case is np.nunique, and the “n” we add to the beginning of the word unique means numeric, and it takes us to the total unique value result.</p><p><strong>array = np.array([2, 1, 5, 2, 1, 3, 5, 3, 4, 4])</strong></p><p><strong>unique_values = np.unique(array)</strong></p><p><strong>print(unique_values)</strong></p><p>Output : <strong>5</strong></p><p>Thus, we have reached the conclusion that we have a total of 5 unique (unique, singular) values in one command with the ease provided by NumPy.</p><p>Other common NumPy functions</p><p><strong>np.sin</strong>: An arrayCalculates the sine values of .<br><strong>np.cos</strong>: Calculates the cosine values of an array.<br><strong>np.tan</strong>: Calculates the tangent values of an array.<br><strong>np.exp</strong>: Calculates the base e exponent of the elements of an array (e^x).<br><strong>np.log</strong>: Calculates the natural logarithm of the elements of an array (ln(x)).<br><strong>np.log10</strong>: Calculates the logarithm of the elements of an array in base 10 (log10(x)).<br><strong>np.sqrt</strong>: Calculates the square root of the elements of an array.<br><strong>np.abs</strong>: Calculates the absolute values of the elements of an array.<br><strong>np.power</strong>: Increases the elements of an array to the specified power.<br><strong>np.sum</strong>: Calculates the sum of the elements of an array.<br><strong>np.mean</strong>: Calculates the average of the elements of an array.<br><strong>np.max</strong>: Finds the largest element of an array.<br><strong>np.min</strong>: Finds the smallest element of an array.<br>I tried to touch on some features of the NumPy library in terms of Data Science.</p><p>Wishing you days full of “Data Science”, which will always be the science of the “now” when the whole future is taken into account!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=deb023d79bcd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/datascienceoffuture/numpy-fundamentals-on-data-science-deb023d79bcd">NumPy Fundamentals on Data Science</a> was originally published in <a href="https://medium.com/datascienceoffuture">datascienceoffuture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>